Zipping everything except a specific folder?

So, there are times, when you want to zip up a while directory, but you may want to exclude just 1 or 2 directories or files. Here is how to do it:

 

$ ls -lrt /tocompress/
total 16
drwxr-xr-x 2 root root 4096 Apr 17 07:38 dir001
drwxr-xr-x 2 root root 4096 Apr 17 07:38 dir002
drwxr-xr-x 2 root root 4096 Apr 17 07:39 dir003
-rw-r–r– 1 root root 8 Apr 17 07:39 test.txt

$ sudo zip -r ~/tocompress.zip /tocompress -x /tocompress/dir002/*
adding: dir001/ (stored 0%)
adding: dir001/dir00/ (stored 0%)
adding: dir003/ (deflated 13%)
adding: test.txt (stored 0%)

$

The above example, compresses the /tocompress folder and stores it in the users’ home directory. It also excludes the dir002 folder and its contents, while the rest of them are compressed.