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