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.
First of all if you don't have installed zip install it first as follows:
Then for simply creating a zip file:
If you want to exclude hidden files:
Excluding Files from a Zip Archive (taken from http://osxdaily.com/2013/04/30/how-to-exclude-files-from-a-zip-archive/)
This also excludes hidden files in unhidden directories:
Add
"
to the.*
(otherwise, your shell expands.*
to the dot files in the current directory), and also exclude hidden files in subdirectories:This will result in files starting with a
.
not to be added into your zip file.Example for excluding all folders begining with . :
Better compress but slower :
This one includes all "." directories, subdirectories, and "." files or directories within directories... Essentially the first answer but includes top level "." files.
The correct method would be:
While zipping dirs excluding some file extension:
Without hidden folders and files in directory:
directory: