I thought I’d create a quick reference of useful zip and unzip commands for those of you that aren’t too familiar doing it via command line.

Definition: zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC OS.

ZIP a File

zip

ZIP and encrypt/password protect a file

$ zip -e

ZIP an entire directory (including all subdirectories)

$ zip -r

ZIP and encrypt/password protect an entire directory (including all subdirectories)

$ zip -re

ZIP all mp3’s within the current directory (includes subdirectories)

$ zip -r foo . -i \*.mp3

ZIP all mp3’s & m4a’s within the current directory (includes subdirectories)

$ zip -r foo . -i \( "*.mp3" "*.m4a" \)

UNZIP

$ unzip .zip

UNZIP all files into the /tmp directory

$ unzip .zip  -d /tmp

List all files within a ZIP file

$ unzip -l .zip

UNZIP a file called work.doc from .zip

$ unzip .zip  work.doc

Test a ZIP file to check whether it has any errors or not
-q = Quiet mode; eliminate informational messages  and  comment  prompts.
-t = Test the integrity of the new zip file.

$ unzip -tq foo.zip
No errors detected in compressed data of foo.zip.

$ unzip -t foo.zip
Archive:  foo.zip
testing:    OK
testing:    OK
testing:    OK
testing:    OK
testing:    OK
No errors detected in compressed data of foo.zip.