22

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.

7ochem
  • 2,183
  • 1
  • 34
  • 42
user1654183
  • 4,375
  • 6
  • 26
  • 33

2 Answers2

53

You need to use the --exclude option:

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

Allolex
  • 700
  • 5
  • 10
1

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
Lily Yung
  • 60
  • 9
Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43