Linux Archiving and Compression: tar, gzip, and zip Compared

Linux’s archiving and compression tools are separate, composable utilities by design — a philosophy worth understanding since it explains why tar commands look the way they do.

# Create a compressed archive (c=create, z=gzip, v=verbose, f=filename)
tar -czvf backup.tar.gz /var/www/mysite

# Extract it
tar -xzvf backup.tar.gz

# List contents without extracting
tar -tzvf backup.tar.gz

# Extract to a specific directory
tar -xzvf backup.tar.gz -C /tmp/restore

# Using bzip2 or xz instead of gzip - better compression, slower
tar -cjvf backup.tar.bz2 /var/www/mysite   # bzip2
tar -cJvf backup.tar.xz /var/www/mysite    # xz - generally best ratio

# zip, for cross-platform compatibility (e.g. sharing with Windows users)
zip -r backup.zip /var/www/mysite
unzip backup.zip

Why tar and gzip Are Separate Tools

tar (“tape archive”) only combines multiple files into one — it doesn’t compress at all on its own. Compression is a separate step (gzip, bzip2, xz), which is exactly why the -z/-j/-J flags exist — they tell tar to pipe its output through a specific compressor, following the classic Unix philosophy of small, composable tools rather than one monolithic archiver.