简体   繁体   中英

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 .

I want to create a SINGLE tarball/gzip file which maintains the directory structure but excludes all files with the *.xdr extension.

How can I do this?

I did something like 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.

您需要使用--exclude选项:

tar -zc -f test.tar.gz --exclude='*.xdr' *

gzip will always handle files individually. 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.

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

tar -T filelist.txt -c -v -f myarchive.tar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM