user1654183 user1654183 - 1 month ago 18
Linux Question

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

Answer

You need to use the --exclude option:

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