So, there are times, when you want to zip up a while directory, and you may want to exclude just 1 or 2 directories or files. There could be couple of ways to do it. Here is how to do it using zip:
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[[email protected]]$ 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%)[[email protected]]$
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.