Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 zipfile.zip directory

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

zip -r zipfile.zip directory -x .*

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

share|improve this question
add comment

4 Answers

up vote 26 down vote accepted

This also excludes hidden files in unhidden directories:

find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
share|improve this answer
    
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-) –  moose Aug 28 '11 at 9:17
add comment

Add " to the .*:

zip -r zipfile.zip . -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 zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*"
updating: tmp/ (stored 0%)
share|improve this answer
1  
I don't think your last statement is correct. .* would get expanded by the shell. –  hammar Aug 27 '11 at 22:11
1  
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 –  moose Aug 28 '11 at 9:13
add comment
ls -A | grep -v '^\.' | zip zipfile.zip -@

this zips all the files in the current directory – but not dot files (nor ANY subdirs).

share|improve this answer
add comment

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 ~/file.zip -@
share|improve this answer
add comment

Your Answer

 
discard

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.