linux - 解压不到一天的文件

标签 linux shell unix tar

所以我一直在研究一种解决方案,可以将来自另一台服务器的新文件解压缩到特定文件夹。 我有单独的解决方案,但试图将它们组合起来。 这是我到目前为止所做的。

find . -name 'BkupFPTCONS*' -mtime -1 | xargs tar -xvf

这将找到不到 24 小时的 tar 文件并提取它们。但是,我需要以省略根文件夹的方式将文件提取到特定文件夹。下面的命令工作正常。但同样,我需要将它与上述命令结合使用来自动执行此过程。

tar -xf BkupFPTCRPOL*.tar.gz -C ./FPTCRPOL --strip-components=1 

非常感谢您的建议。

最佳答案

试试这个:

find . -name 'BkupFPTCONS*' -mtime -1 -execdir tar -xf {} -C ./FPTCRPOL --strip-components=1 \;

注意 -execdir,来自 man:

-execdir utility [argument ...] ;
         The -execdir primary is identical to the -exec primary with
         the exception that utility will be executed from the directory
         that holds the current file.  The filename substituted for 
         the string ``{}'' is not qualified.

如果您想在提取内容后删除压缩文件,您可以使用 -delete 选项:

find . -name 'BkupFPTCONS*' -mtime -1 \
    -execdir tar -xf {} -C ./FPTCRPOL --strip-components=1 \; -delete 

关于linux - 解压不到一天的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46534520/

相关文章:

linux curl 重定向和授权

linux - 在 Ubuntu 上安装 Gnuplot 5.0

linux - 为什么两个不同系统之间的 apache2 中每个进程使用的内存差异如此之大?

c - 在 c 中实现子 shell

bash - 在 Bash 中传递 -e 和 -n 作为位置参数

c - Linux/将目录作为文件打开

linux - 使用 awk 时如何识别搜索字符串中的制表符空间?

c - 为什么具有自定义函数的 rl_bind_key 在 OSX/macOS 上的 readline 中失败

c++ - 混合 c 和 c++ 库(多 Unix 平台)

c - 在 C 中设置 open() 系统调用的权限