tar/gzip excluding certain files tar/gzip excluding certain files bash bash

tar/gzip excluding certain files


You need to use the --exclude option:

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