how to exclude directories and file zipping a directory?
I, need to zip a directory excluding some subdirectory and file; I used this:
zip -r zipfile.zip . -x ".*" -x "app/bower_components" -x "node_modules" -x "*.zip" -x "node_modules"
without any success; node_modules
is a folder in the principal one while bower_components
is inside the folder app
Solution 1:
I simply make a guess what you want.
-x ".*"
exclude all files beginning with a dot
do it like:
-x .\*
exclude all files (with a dot in the filename)
do it like:
-x \*.\*
--
-x "app/bower_components" -x "node_modules"
exclude this directory and all files in it
do it like:
-x app/bower_components/\* -x node_modules/\*
--
-x "*.zip"
exclude all zip-Files
do it like:
-x \*.zip
You exclude node_modules twice
Solution 2:
Assuming your directory is a git repository (and judging by the question, it very likely is), you can add directories that you want to exclude to the .gitignore
file and use the git archive
command to zip contents of your directory:
git archive --format=zip HEAD -o zipfile.zip
In your example, the .gitignore
file would have to look like this:
node_modules
app/bower_components
Solution 3:
exclude all node_modules folders in all folders.
zip -r node.zip . -x "**/node_modules/*"
Solution 4:
Something like this should do the trick:
zip -r zipped.zip dir1/ -x */\.* *.git* \.* *.zip *.csv *.json *.rb *.bak *.swp *.back *.merge *.txt *.sh dir1/node_modules/**\* dir1/bower_components/**\* dir1/dist/**.*
Where following -x
is a list of directories and file (extension) types to exclude.