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


The following will do

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

What did you need the ** for, @sulman?

It works like a charm for me as follows:

[root@ip-00-000-000-000 dir1]# ls -lrt dir1/ 
total 16
drwxr-xr-x 2 root root 4096 Oct 31 07:38 ignoredir1
drwxr-xr-x 2 root root 4096 Oct 31 07:38 ignoredir2
drwxr-xr-x 2 root root 4096 Oct 31 07:39 dir3
-rw-r--r-- 1 root root    8 Oct 31 07:39 test.txt

[root@ip-00-000-000-000 temp]# zip -r dir1.zip dir1 -x dir1/ignoredir1\* dir1/ignoredir2\*
  adding: dir1/ (stored 0%)
  adding: dir1/dir3/ (stored 0%)
  adding: dir1/dir3/test3.txt (deflated 13%)
  adding: dir1/test.txt (stored 0%)