Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make a zip of all the files and subdirectories in the directory mydir, except all those files/dirs that begin with a .*?

The command:

zip -r mydir/

...will include everything. For example, if I have:


I'd like foo and bar to be included in mydir, but not .hello.

How can I do this?

share|improve this question
up vote 4 down vote accepted

This works for me:

zip -r mydir -x "*/.*"

@Joe Internet, @Dariusz: normal shell patterns won't work properly because zip matches against the full path+filename internally (as the zip manual explains... ;) )

share|improve this answer
Claeys - My example workerd for me, but to be fair, I used Ch Shell (includes zip) under Win7. I CDed into my test directory, and used 'zip -r ./ -x .*.*' (minus the single quotes). If I use 'zip -r mydir -x "/."' (minus the single quotes), it doesn't exclude the hidden file in my test directory. I guess it's down to differences in the shells used to test with. – Joe Internet Aug 22 '10 at 19:01

You can use shell patterns to exclude matches, all is written in zip manual (with examples)

share|improve this answer

If you prefer more complex filtering capabilities, find is a good tool:

find mydir/ -! -name ".hello" -print | zip mydir -@

Have fun with 'find'.

share|improve this answer

Try this...

zip -r mydir/ -x .*.*
share|improve this answer

Shorter, and takes advantage of the features of globbing:

zip -r mydir/*

(. files are not included in the * wildcard)

Note that the directory 'mydir/' may not be included in the paths of the files in the resultant zip file, so this will change the output slightly. You may have to change your extraction process as a result.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .