Skip to content
# Files, text & logs

Archives & compression: tar, gzip, zip

Bundle and compress files for backups and transfers.

tar: the standard archive format

tar bundles files and directories into a single archive. Combined with -z it also gzip-compresses the result β€” the standard .tar.gz you'll see everywhere.

bash
tar -czvf backup.tar.gz /etc/nginx     # create (c)ompressed, (v)erbose, to (f)ile
tar -xzvf backup.tar.gz -C /restore    # e(x)tract into /restore

List an archive without extracting

Use -t (list) instead of -x to see what's inside an archive before committing to extracting it.

bash
tar -tzvf backup.tar.gz

gzip: compress a single file

gzip compresses one file at a time and replaces it with a .gz version by default; -k keeps the original. gunzip (or gzip -d) reverses it.

bash
gzip -k access.log
gunzip access.log.gz

zip / unzip

Not installed by default on most minimal server images, but useful when you need a .zip specifically (e.g. exchanging files with Windows users).

bash
sudo apt install zip unzip   # or dnf/zypper/apk/pacman
zip -r site.zip /var/www/html
unzip site.zip -d /restore