I would like to zip the directory but exclude some subdirectories. Let's say I have such structure:

   subdirectory 1
   subdirectory 2
     project 1
         directory 1 
         ... (other directories)
     project 2
         directory 2 
         ... (other directories) 

I would like to ZIP the whole main directory but I would like to exclude paths like this:



  • * - is one-level directory
  • ** - is directory with any files and subdirectories

The problem is that those project 1 and project 2 are quite dynamic - there are multiple of them. Also notice that vendor directories (and also in theory node_modules) can be placed in some other places for example in project 1/html/public/vendor so I wouldn't like to exclude just vendor subdirectory but only specific vendor subdirectory that is located exactly in given html directories of projects.

Is it possible to make such complex thing using just zip command or maybe some bash script should be written for this?

I'm using MacOS if it makes any difference.

What I've achieved so far is:

cd directory && zip test-zip.zip  * -r -T -x */*/html/vendor/** */*/html/node_modules/**

It seems it almost works but it creates empty vendor and node modules directories (but not include their content)


It seems solution is:

cd directory && 
zip test-zip.zip  * -r -T -x "*/*/html/vendor/" "*/*/html/node_modules/" "*/*/html/vendor/**" "*/*/html/node_modules/**"

so I exclude everything in this directories and those directories too and also wrap everything in quotes to be expanded in valid way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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