[英]tar/gzip excluding certain files
I have a directory with many sub-directories. 我有一个包含许多子目录的目录。 In some of those sub-directories I have files with
*.asc
extension and some with *.xdr
. 在某些子目录中,我的文件扩展名为
*.asc
而某些文件的扩展名为*.xdr
。
I want to create a SINGLE tarball/gzip file which maintains the directory structure but excludes all files with the *.xdr
extension. 我想创建一个SINGLE tarball / gzip文件来维护目录结构但排除所有扩展名为
*.xdr
文件。
How can I do this? 我怎样才能做到这一点?
I did something like find . -depth -name *.asc -exec gzip -r9 {} +
我做了像
find . -depth -name *.asc -exec gzip -r9 {} +
东西find . -depth -name *.asc -exec gzip -r9 {} +
find . -depth -name *.asc -exec gzip -r9 {} +
but this gzips every *.asc
file individually which is not what I want to do. find . -depth -name *.asc -exec gzip -r9 {} +
但这会单独*.asc
每个*.asc
文件,这不是我想要做的。
您需要使用--exclude
选项:
tar -zc -f test.tar.gz --exclude='*.xdr' *
gzip will always handle files individually. gzip将始终单独处理文件。 If you want a bundled archive you will have to tar the files first and then gzip the result, hence you will end up with a .tar.gz file or .tgz for short.
如果你想要一个捆绑的存档,你必须首先tar文件然后gzip结果,因此你最终会得到一个.tar.gz文件或.tgz。
To get a better control over what you are doing, you can first find
the files using the command you already posted (with -print instead of the gzip command) and put them into a file, then use this file (=filelist.txt) to instruct tar with what to archive 为了更好地控制您正在做的事情,您可以先使用已发布的命令(使用-print而不是gzip命令)
find
文件并将它们放入文件中,然后使用此文件(= filelist.txt)指示tar存档的内容
tar -T filelist.txt -c -v -f myarchive.tar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.