Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.

I know that I can create a zip archive of a directory like this:

zip -r directory

I also know that I can exclude files with the -x option, so I thought this might work:

zip -r directory -x .*

It didn't work. All hidden directories were still in the zip-file.

share|improve this question
up vote 56 down vote accepted

This also excludes hidden files in unhidden directories:

find /full_path -path '*/.*' -prune -o -type f -print | zip ~/ -@
share|improve this answer
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/ -@) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-) – Martin Thoma Aug 28 '11 at 9:17
Thanks. And looks like it works on OS X, too. – Sarge Borsch Nov 20 '15 at 8:15

Add " to the .* (otherwise, your shell expands .* to the dot files in the current directory), and also exclude hidden files in subdirectories:

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

This will result in files starting with a . not to be added into your zip file.

rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x  2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x  2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
share|improve this answer
I don't think your last statement is correct. .* would get expanded by the shell. – hammar Aug 27 '11 at 22:11
I think it is likely to be correct but I removed it (not sure about it) :) – Rinzwind Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added – Martin Thoma Aug 28 '11 at 9:13
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude */.* as well as .* (*/ matches any non-empty sequence of directories). – Gilles May 8 '14 at 17:21

First of all if you don't have installed zip install it first as follows:

sudo apt-get install zip

Then for simply creating a zip file:

zip -r foldername

If you want to exclude hidden files:

find folder_path/ -path '*/.*' -prune -o -type f -print | zip ~/ -@
share|improve this answer
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal. – hmayag Aug 11 '15 at 7:04
Thanks for the suggestion – M A K Ripon Jun 16 at 9:00

This one includes all "." directories, subdirectories, and "." files or directories within directories... Essentially the first answer but includes top level "." files.

find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/ -@
share|improve this answer

The correct method would be:

zip -r directory -x directory/.*
share|improve this answer
@downvoter: What's wrong, this seems to be working for me. – i08in May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them. – Gilles May 8 '14 at 17:25

While zipping dirs excluding some file extension:

$ cd /path/to/dir
$ zip -r . -x "*.log" -x "*.cache"
share|improve this answer

Example for excluding all folders begining with . :

tar cvpzf folder.tgz folder/ --exclude '.*'

Better compress but slower :

tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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