1

I want to exclude all .zip files in all subdirectories of the parent folder I'm zipping but I doesn't work. I have check the man zip pages, this and this questions without success.

I have tried:

zip -q -r FILE.zip * -x \*.zip
zip -q -r FILE.zip * -x\*.zip
zip -q -r FILE.zip * -x */\.zip
zip -q -r FILE.zip * -x \*.zip
zip -q -r FILE.zip * -x \*.zip\*
zip -q -r FILE.zip * -x*.zip

and I still get all zip files included (except the one in the parent folder generated with this command before).

EDIT: The problem was that I already had a FILE.zip in the folder which included some zip files. The zip command updates instead of creates a new compressed file if the file it attempts to create already exist, even if you don't indicate the -u option.

1 Answers1

2

You need to quote the exclude pattern, as you already tried to do; The first one should actually work, even if there is a "nicer" solution.

But let's look at a simplified example to work with; I Created some directories with files with .foo and .bar extensions:

Here I run find to list my test directory - it shows all files and directories:

$ find
.
./1.bar
./1.foo
./sub1
./sub1/sub2
./sub1/sub2/1.bar
./sub1/sub2/1.foo
./sub1/1.foo
./sub1/1.bar

Now, we can just see what works
(we get the output file out of the way, its not relevant to the matching).

Packing all files:

$ zip -r /tmp/out.zip *          
  adding: 1.bar (stored 0%)
  adding: 1.foo (stored 0%)
  adding: sub1/ (stored 0%)
  adding: sub1/sub2/ (stored 0%)
  adding: sub1/sub2/1.bar (stored 0%)
  adding: sub1/sub2/1.foo (stored 0%)
  adding: sub1/1.foo (stored 0%)
  adding: sub1/1.bar (stored 0%)

Packing excluding .foo files:

$ rm /tmp/out.zip
$ zip -r /tmp/out.zip * -x '*.foo'
  adding: 1.bar (stored 0%)
  adding: sub1/ (stored 0%)
  adding: sub1/sub2/ (stored 0%)
  adding: sub1/sub2/1.bar (stored 0%)
  adding: sub1/1.bar (stored 0%)

Works!
Trying again with your first pattern:

$ rm /tmp/out.zip
$ zip -r /tmp/out.zip * -x \*.foo 
  adding: 1.bar (stored 0%)
  adding: sub1/ (stored 0%)
  adding: sub1/sub2/ (stored 0%)
  adding: sub1/sub2/1.bar (stored 0%)
  adding: sub1/1.bar (stored 0%)

Works too!

So... take a close look at what you really did run there.

First you could remove the -q option for "quiet", hiding the standard messages shown in my examples.
As a next step, add the -v option for "verbose", to see more details - maybe too many, but maybe you can spot something interesting.


From the comments I see that removing the -q already helped;

The underlying problem was that the zip command used for testing was modified by the existence of the output file.
Technically, it had modified itself even...

From man zip:

Command format.  The basic command format is

               zip options archive inpath inpath ...

        where archive is a new or existing zip archive and inpath is a directory or
        file path optionally including wildcards.  When given the name of an exist‐
        ing zip archive, zip will replace identically named entries in the zip  ar‐
        chive (matching the relative names as stored in the archive) or add entries
        for new names.
Volker Siegel
  • 13,295