bash - 找到上次创建的 tar.gz 并解压

标签 bash centos find extract xargs

我需要找到最后创建的 tar.gz 文件并将其解压到某个目录,如下所示:

ls -t $(pwd)/Backup_db/ | head -1 | xargs tar xf -C /somedirectory

如何在 CentOS 7 中以正确的方式做到这一点?

最佳答案

您可以在子 shell 中找到最近编辑的文件,然后用它代替文件名。可以创建新目录,然后可以将 tar 文件提取到该目录。

new_dir="path/to/new/dir"
mkdir -p $new_dir
tar -zxvf $(ls -t *.tar.gz | head -1) -C $new_dir

关于bash - 找到上次创建的 tar.gz 并解压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51721731/

相关文章:

shell - 我正在尝试通过ssh-入服务器列出(ls)文件夹。是否有任何命令将输出存储为数组?

bash - 如何使任何 sed、awk 和 grep 命令忽略以# 开头的行?

python - centOs 7在搜索依赖项时找不到python3-PyYAML和python3-gobject

postgresql - CloudLinux 7.8 错误安装 postgresql 11 需要 : llvm-toolset-7-clang >= 4. 0.1

linux - 需要帮助在 CentOS 5.5 上设置 Apache,得到 403

C++ 测试字符串的最后一个字符

c++ - find() 是否也返回 C++ 中映射的最后一个元素?

python - 如何在 Jupyter Notebook 终端中激活 conda virtualenv?

linux - 从 Linux Bash Shell 配置 NIC

bash - 从 crontab 中调用执行期望的 bash 脚本