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, need to zip a directory excluding some subdirectory and file; I used this:

zip -r . -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

share|improve this question
what is your result and what are your expected result? – D-E-N Nov 5 '13 at 17:57
You want to exclude all subdirectories or only some of them ? – Serg Jun 10 '15 at 17:16

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

share|improve this answer
thanks I got it, using various post arrived to that: zip -r * app/* -x\app/bower_components/* -x\node_modules/* -x*.zip – arpho Nov 7 '13 at 15:34
@arpho Your comment above should be an answer as it appears to be working for me... – chesedo Jun 22 at 11:48

Something like this should do the trick:

zip -r 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.

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.