*.zip patterns work in
tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir
Is there another syntax?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You will need to quote the exclusion pattern,
mydir/files/*.zip, otherwise the shell will expand it (globbing), possibly/probably matching a number of files, and the meaning of you command line will be very different from what you intended.
This means changing you original
tar command line into
$ tar cfjv backup.tar.bz2 --exclude "mydir/files/*.zip" mydir
I initially thought there was something up with the
cfjv switches. These are ancient command line switches and
tar handles them very differently from more "modern" command line switches (prefixed by
-). That's why you do not get an archive called
jv even though that's what's following the
The manual for
tar on Mac OS X mentions this under the "COMPATIBILITY" section:
The bundled-arguments format is supported for compatibility with historic implementations. It consists of an initial word (with no leading - character) in which each character indicates an option. Arguments follow as separate words. The order of the arguments must match the order of the corresponding characters in the bundled command word. For example,
tar tbf 32 file.tar
specifies three flags t, b, and f. The b and f flags both require arguments, so there must be two additional items on the command line. The 32 is the argument to the b flag, and file.tar is the argument to the f flag.
To search for all .zip files in current directory and all sub-directories try: this
find ./foldername -type f -name '*.zip'
To Exclude all .zip files in current directory and all sub-directories try this:
find ./foldername -type f -name '*.zip' > exclude.txt
To Create tar Archive excluding all .zip files in current directory and all sub-directories try this:
tar -zcvf backup_foldername.tar.gz -X exclude.txt ./foldername