Zip files or directories

Replace filename with the name you want to give the zip file. The .zip extension is automatically appended to the end of the filename. Replace inputfile1 and inputfile2 with the names of the files you wish to include in the zip archive. You can include any number of files here, or you may use an asterisk (*) to include all files in the current directory.

# to choose individual files 
# to include in the zip
zip filename inputfile1 inputfile2

# To include the contents of a directory 
# or directories in a zip archive, 
# use the  -r  flag:

zip -r filename directory

#or

zip -r filename *

To ignore files based on a pattern, then do the following:

zip -r backup.zip folderName -x "*.DS_Store"

This would ensure no pesky .DS_Store files wind up in the zip.

If you need to exclude specific directories:

zip -r backup.zip ./* -x ./system\*

This would zip everything minus the system directory and everything in it. Multiple directories can be specified like this:

zip -r backup.zip ./* -x ./2008\* ./2009\* ./2010\* ./2011\*
Snippets and tagged