2

Why don't *.zip patterns work in tar :

tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir

Is there another syntax?

  • 2
    What is the output of that command? Don't you have to have the f flag last before the archive name, i.e. cjvf backup.tar.z2? Otherwise it would probably create an archive called jv. – Kusalananda May 31 '15 at 13:58
  • 4
    Try quoting the exclusion pattern, i.e. use --exclude "mydir/files/*.zip". – Kusalananda May 31 '15 at 14:13
  • @Kusalananda : no, cfjv works perfectly – Basj May 31 '15 at 19:30
  • @Kusalananda It works with quotes: --exclude "mydir/files/*.zip" , thanks! – Basj May 31 '15 at 19:31
  • Good! Yes, I saw later in the manual for tar that those very old-style command line switches are handled differently. – Kusalananda May 31 '15 at 19:48
3

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 f switch.

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.