Zip recursive with excluding some directories
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
Related videos on Youtube
Marcin Nabiałek
I'm a Cerified Laravel Developer & Zend Certified PHP Engineer experienced in making code reviews. If you need remote Laravel PHP developer or you are looking for someone to help you to keep high code quality, feel free to contact. Learn more about me at Marcin Nabiałek - Laravel PHP developer
Updated on September 18, 2022Comments
-
Marcin Nabiałek over 1 year
I would like to zip the directory but exclude some subdirectories. Let's say I have such structure:
directory subdirectory 1 subdirectory 2 project 1 html directory 1 vendor node_modules ... (other directories) project 2 html directory 2 vendor node_modules ... (other directories)
I would like to ZIP the whole main directory but I would like to exclude paths like this:
subdirectory2/*/html/vendor/** subdirectory2/*/html/node_modules/**
where:
*
- is one-level directory**
- is directory with any files and subdirectories
The problem is that those
project 1
andproject 2
are quite dynamic - there are multiple of them. Also notice thatvendor
directories (and also in theorynode_modules
) can be placed in some other places for example inproject 1/html/public/vendor
so I wouldn't like to exclude justvendor
subdirectory but only specificvendor
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)