Linux offers a half-dozen solid compression tools, each with different trade-offs between speed, compression ratio, and compatibility. Picking the right one depends on your use case – archiving logs for long-term storage is a different problem than compressing files for fast network transfer. This guide covers all the major options, their maximum compression flags, realistic performance comparisons, and parallel compression tools that take advantage of multi-core systems.

Quick Comparison Table

Before diving into details, here is the summary. Compression ratio and speed vary by data type, but these are representative rankings for typical mixed workloads:

ToolMax FlagCompression RatioSpeedParallel Version
zip-9Low-MediumFastN/A
gzip-9MediumFastpigz
bzip2-9Medium-HighSlowpbzip2 / lbzip2
xz-9eHighVery Slowpxz / xz -T0
zstd-19 / --ultra -22HighFastBuilt-in (-T0)

zip – The Universal Format

zip is the most widely compatible format. Every operating system can open zip files without installing extra software. It creates an archive (multiple files in one container) and compresses in a single step.

Maximum compression:

zip -9 -r archive.zip /path/to/directory

The -9 flag sets the highest compression level (deflate algorithm). The difference between -1 and -9 is usually modest – maybe 5-10% smaller files – but compression time increases noticeably.

Verify the archive:

zip -T archive.zip

When to use zip: sharing files with Windows or macOS users, email attachments, or any situation where the recipient might not have Linux tools installed.

Install on Linux if missing:

# RHEL / Rocky / Alma
sudo dnf install zip unzip

# Ubuntu / Debian
sudo apt install zip unzip

gzip – The Linux Default

gzip is the standard compression tool on Linux. It compresses a single file and replaces the original with a .gz version. It does not create archives – you combine it with tar for that.

Maximum compression:

gzip -9 filename.log

Keep the original file:

gzip -9 -k filename.log

Decompress:

gzip -d filename.log.gz
# or
gunzip filename.log.gz

Check integrity:

gzip -t filename.log.gz

When to use gzip: log rotation, quick single-file compression, web server content encoding (nginx and Apache support gzip natively), and any pipeline where speed matters more than ratio.

bzip2 – Better Ratio, Slower Speed

bzip2 uses the Burrows-Wheeler algorithm, which achieves better compression ratios than gzip at the cost of significantly slower speed. Like gzip, it operates on single files.

Maximum compression:

bzip2 -9 filename.log

Keep the original:

bzip2 -9 -k filename.log

Decompress:

bzip2 -d filename.log.bz2
# or
bunzip2 filename.log.bz2

Verify:

bzip2 -t filename.log.bz2

When to use bzip2: it has largely been superseded by xz (better ratio) and zstd (better speed and ratio). You will still encounter .bz2 files in older source tarballs and some distribution packages.

xz – Maximum Compression

xz uses the LZMA2 algorithm and typically produces the smallest files of any tool on this list. The trade-off is that it uses substantial CPU time and memory, especially at higher levels.

Maximum compression:

xz -9e filename.log

The -e flag enables “extreme” mode, which tries additional compression strategies. At level 9e, xz can use over 600 MB of RAM for compression.

Keep the original:

xz -9e -k filename.log

Decompress:

xz -d filename.log.xz
# or
unxz filename.log.xz

Verify:

xz -t filename.log.xz

When to use xz: distributing software packages (kernel tarballs, distro packages), archiving data for long-term storage where compression time is irrelevant but storage cost matters.

zstd – The Modern Choice

Zstandard (zstd) was developed by Facebook and has quickly become the preferred compression tool for many Linux distributions. It offers an excellent balance of speed and compression ratio, and it scales across a wide range of levels.

Default compression (level 3 – fast with decent ratio):

zstd filename.log

High compression:

zstd -19 filename.log

Maximum possible compression:

zstd --ultra -22 filename.log

The --ultra flag unlocks levels 20-22. At level 22, zstd approaches xz compression ratios but with faster decompression.

Keep the original:

zstd -19 -k filename.log

Decompress:

zstd -d filename.log.zst
# or
unzstd filename.log.zst

Verify:

zstd -t filename.log.zst

Install zstd:

# RHEL / Rocky / Alma
sudo dnf install zstd

# Ubuntu / Debian
sudo apt install zstd

When to use zstd: database backups, container image layers, log compression, real-time compression in filesystems (Btrfs supports zstd natively), and anywhere you want a good ratio without the glacial speed of xz. Fedora, Ubuntu, and Arch already use zstd for package compression.

Combining tar with Compression

All the tools above (except zip) compress single files. To archive a directory and compress it, combine them with tar:

# tar + gzip
tar czf archive.tar.gz /path/to/directory

# tar + bzip2
tar cjf archive.tar.bz2 /path/to/directory

# tar + xz
tar cJf archive.tar.xz /path/to/directory

# tar + zstd
tar --zstd -cf archive.tar.zst /path/to/directory

To pass compression level flags through tar, use the -I option to specify the compressor explicitly:

# tar + gzip level 9
tar -I 'gzip -9' -cf archive.tar.gz /path/to/directory

# tar + xz extreme level 9
tar -I 'xz -9e' -cf archive.tar.xz /path/to/directory

# tar + zstd level 19
tar -I 'zstd -19' -cf archive.tar.zst /path/to/directory

Verify the archive contents:

tar tzf archive.tar.gz | head -20

Parallel Compression Tools

Single-threaded compression leaves most of your CPU idle. Parallel implementations split the input into blocks and compress them across all available cores, dramatically reducing wall-clock time on multi-core servers.

pigz – Parallel gzip

# Install
sudo dnf install pigz    # RHEL-family
sudo apt install pigz     # Debian-family

# Compress with all cores at max level
pigz -9 -p $(nproc) filename.log

# Use with tar
tar -I 'pigz -9' -cf archive.tar.gz /path/to/directory

pigz produces files that are fully compatible with gzip – you can decompress them with regular gunzip.

pbzip2 and lbzip2 – Parallel bzip2

# Install
sudo dnf install pbzip2    # RHEL-family
sudo apt install pbzip2    # Debian-family

# Compress with all cores
pbzip2 -9 -p$(nproc) filename.log

# Use with tar
tar -I 'pbzip2 -9' -cf archive.tar.bz2 /path/to/directory

lbzip2 is an alternative that is often faster than pbzip2 for decompression:

sudo dnf install lbzip2
tar -I lbzip2 -cf archive.tar.bz2 /path/to/directory

xz with Built-in Threading

Modern versions of xz (5.2+) support multi-threading natively with the -T flag:

# Use all available cores
xz -9e -T0 filename.log

# Use with tar
tar -I 'xz -9e -T0' -cf archive.tar.xz /path/to/directory

The -T0 flag tells xz to use as many threads as there are CPU cores. Note that multi-threaded xz uses significantly more memory – roughly the single-thread requirement multiplied by the thread count.

zstd with Built-in Threading

zstd has native multi-threading support, making it the easiest tool to parallelize:

# Use all cores
zstd -19 -T0 filename.log

# Use with tar
tar -I 'zstd -19 -T0' -cf archive.tar.zst /path/to/directory

Verify the result:

zstd -t archive.tar.zst && echo "Archive is valid"

Choosing the Right Tool

Here are practical guidelines based on common scenarios:

  • Daily log compression / rotation – Use gzip (or pigz on multi-core systems). Fast, universal, good enough ratio.
  • Database backups – Use zstd at level 3-9 with -T0. Best speed-to-ratio trade-off for large files.
  • Software distribution / package building – Use xz or zstd. Both are standard in package managers.
  • Long-term archival storage – Use xz -9e. Smallest files, decompression speed is irrelevant for cold storage.
  • Cross-platform sharing – Use zip. Everyone can open it without extra tools.
  • Real-time filesystem compression – Use zstd (Btrfs) or lzo/zlib (ZFS). These operate transparently at the filesystem level.
  • Network transfer – Compress with zstd at a low level (1-3) for near-wire-speed compression. The decompression is extremely fast.

Summary

There is no single best compression tool – the right choice depends on whether you are optimizing for size, speed, compatibility, or memory usage. For most server workloads in 2026, zstd hits the sweet spot between compression ratio and throughput, with native multi-threading that fully utilizes modern hardware. Use gzip when compatibility matters, xz when every byte counts, and zip when the recipient is on Windows. Whatever you choose, always verify your compressed files after creation – a corrupt archive is worse than no archive at all.

2 COMMENTS

  1. I followed this on Linux Mint. The results were outstanding, 68M down to 12K. Then I opened the file and found there was nothing inside it. I found that you need to use `-r` for recursive. So the command that worked for me was `zip -9 -r desktop.zip Desktop`

  2. I used the following command:

    zip -FS9r example.zip example

    According to “du -sh,” the example folder is 23 gigs, and the zip file is 22 gigs…

    Is there no way to achieve higher compression by using another zip flag?

LEAVE A REPLY

Please enter your comment!
Please enter your name here