ZIP & UNZIP Files & Directories


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 [FILENAME].zip [FILE1] [FilE2] [FILEn]

ZIP an entire directory (including all subdirectories)

zip -r [FILENAME].zip [/PATH/TO/DIRECTORY]

ZIP and password protect a file

Password protect file (considered insecure because of clear-text on the command line).

zip -P [PASSWORD] [FILENAME].zip [FILENAME]ZIP and password protect a file

ZIP and password protect a directory

Password protect file (considered insecure because of clear-text on the command line).

zip -P [PASSWORD] -r [FILENAME].zip [DIRECTORY]/

ZIP and encrypt/password protect a file

zip -e [FILENAME].zip [FILENAME]

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

zip -e -r [FILENAME].zip [DIRECTORY]/

UNZIP

unzip [FILENAME].zip

UNZIP all files into the /tmp directory

unzip [FILENAME].zip -d /tmp

List all files within a ZIP file

unzip -l [FILENAME].zip

UNZIP a file called work.doc from .zip

unzip [FILENAME].zip work.doc

Test a ZIP file

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 [FILENAME].zip

Example

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.