Unix zip directory but excluded specific subdirectories (and everything within them)

I was so close!

The actual command I need is:

zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*

For my particular system in order to exclude a directory I had to put quotes around my excluded directories and it worked like a charm:

zip -r myarchive.zip dir1 -x "dir1/ignoreDir1/*" "dir1/ignoreDir2/*"

Notes:

-- this excluded both the directory to exclude and all files inside it.

-- You must use the full path to the directories you want to exclude!


@sulman using:

     zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*

will still include dir1/ignoreDir1/ empty folder in the zip archive, using:

     zip -r myarchive.zip dir1 -x dir1/ignoreDir1** dir1/ignoreDir2**

will do the trick, you can also use a leading ** to search in subfolders instead of only dir1

Tags:

Unix

Zip

Exclude