$ Linux Commands

Archiving — Compressing and extracting files

gzip Archiving

Compress files using gzip

gzip [OPTIONS] FILE
gzip file.txt
gzip -d file.txt.gz
gzip -k file.txt
-d decompress
-k keep original file
-9 best compression
-1 fastest compression
tar Archiving

Archive files (tape archive)

tar [OPTIONS] FILE...
tar -czvf archive.tar.gz /path/to/dir
tar -xzvf archive.tar.gz
tar -tzvf archive.tar.gz
tar -xzvf archive.tar.gz -C /dest/
-c create archive
-x extract archive
-t list contents
-z gzip compression
-j bzip2 compression
-v verbose
-f specify filename
-C extract to directory

Memory aid: "eXtract Ze Files" for xzf. "Create Ze Files" for czf.

unzip Archiving

Extract compressed files from a ZIP archive

unzip [OPTIONS] ZIPFILE
unzip archive.zip
unzip archive.zip -d /dest/
unzip -l archive.zip
-d DIR extract to directory
-l list contents without extracting
zip Archiving

Package and compress files

zip [OPTIONS] ZIPFILE FILE...
zip archive.zip file1.txt file2.txt
zip -r archive.zip /path/to/dir
-r recursive
-e encrypt with password
-9 best compression