#92: zip command exclude .svn directories

Solved!
I am looking for the command line incantation for zip to package up a .zip file but exclude any .svn metadata directories and files. I used --exclude=.svn/* but it doesn't seem to work.

The gotcha for zip --exclude is to treat the entire relative path as the original string

12
The correct incantation is
zip -9 -r --exclude=*.svn* foo.zip [directory-to-compress]

You can also add a
--exclude=*.DS_Store* to exclude the annoying Mac OS X directory display metadata files.

Notice that the expression passed to --exclude is using the entire original relative directory path as the original string to match against. So .svn/* by itself doesn't work; the wildcard character in front ensures that it matches .svn directories anywhere in the directory tree.

Comments

  1. But we need to use quotes, lest the shell processes the wildcards before zip sees them:

    zip -9 -r "--exclude=*.svn*" foo.zip [directory-to-compress]

    ronald on November 28, 2014, 03:48 PM UTC

Think you've got a better solution? Help 92049143cabb7ba896d7c06e19906303_small yliu out by posting your solution