How to: Exclude files from a ZIP archive

opensuse v11.2, linux 2.6.31.12-0.1-desktop x86_64
ZIP v2.32

I thought I knew ZIP pretty well. Hah!

I wish to exclude some files from a zip archive. On other OSes to exclude an entire directory I would use the “-x” option like so:

zip -r archive-name * -x dir1/*

Simple. And just add “-x”'s as needed (or use an exclusion file).

Not how it works here, it would seem. AFAICT all “-x” options are ignored. (The entries in an exclusion file also.) For instance, “-x diy/mplayer/*” should ignore everything in the <diy/mplayer> directory. It does not. I have tried fully qualified paths as well; no joy.

What is different about ZIP on linux?
Can files be excluded?
What am I missing?

Try quoting the exclude argument:

-x ‘dir1/*’

ken yap wrote:

>
> Try quoting the exclude argument:
>
> -x ‘dir1/*’
>
or escape the * with a backslash to avoid shell filename substitution.

-x dir1/*

jimoe666 wrote:
> What am I missing?

missing: should not expect zip to be the same as on the other system…

and, maybe missed that Linux comes with a complete manual on all the
switches and magic available for zip…

the easy way to read the zip manual is to open a terminal and type


man zip

personally i like to read it in konqueror, all pretty and nicely
formatted, if you have konqueror try


#zip

and, if you wanna know more about the manuals,


#man

and, there are LOTS of other manuals: cp, rm, mount, fsck, ps, top,
zypper, etc etc etc etc

Have a lot of fun!


palladium

Okay, quoting the strings or escaping the wildcard works on the command line. Thanks!

How do I get the same result when using an exclude file?

And, yes, quoting/escaping were mentioned in the man page. I missed it since it was tucked away under the “-d” option description.

jimoe666 wrote:
> How do I get the same result when using an exclude file?

have you tried it exactly the way the man lays it out in one line, and
it didn’t work?

can you give an example of what didn’t work…

> quoting/escaping were mentioned in the man page. I missed it
> since it was tucked away under the “-d” option description.

if you launch the zip man in konqueror you can then Ctrl+f and a
search box will pop up, into which you can type ‘exclude’ . . .

or, if you prefer the CLI you can:

man zip | grep -i exclude


palladium

have you tried it exactly the way the man lays it out in one line, and it didn’t work?

It works on the command line, either quoted or escaped, for multiple “-x” options.

It is a bit confusing since “zip -r * archive …” works but “zip -r ‘’ archive …" does not (“file * not found”). I tried finessing it with "zip -r './’ archive …”; no go there.

For the exclude file the man page indicates each pattern is on a separate line. I would swear that I tried non-quoted or non-escaped strings for each line entry. Apparently I did not since it now works as expected.

Some things are meant to be quoted/escaped and some not. Filename arguments should not be quoted since you want the shell to expand the pattern. However exclude arguments should be quoted because you want the pattern to survive into the zip program where it will be used as a pattern.

One is a shell glob, the other is a regex pattern. The difference is who is meant to interpret it. That dictates whether it should be quoted or not.