tar/gzip excluding certain files

user1654183 picture user1654183 · Aug 1, 2013 · Viewed 26.6k times · Source

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 {} + but this gzips every *.asc file individually which is not what I want to do.

Answer

Allolex picture Allolex · Aug 1, 2013

You need to use the --exclude option:

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