Bash – Excluding a directory when zipping files

bashscriptingzip

I've got a bash script that does something like this:

zip -0 ../backup/backup.zip \
-r ./* \
-x \*CVS\* \
-x *Thumbs.db* \

The directory it's backing up is a SVN archive (it used to be CVS back in the day). I've been unable to get it to exclude .svn and it's contents. What's the cleanest way to exclude .svn (recursively through the entire tree)?

Best Answer

zip -0 ../backup/backup.zip -r . -x "*CVS*" "*Thumbs.db*" "*.svn*"

-x also accepts a list of excludes.

Alternatively, create a filelist with your excludes and add them there.
The exclude.lst:

*CVS*
*Thumbs.db*
*.svn*
exclude.lst

with the command:

zip -0 ../backup/backup.zip -r . -x@exclude.lst
Related Question