zstd compressed a 1.7 GB kernel source tar in 4.95 seconds on one core. GNU gzip needed 35.69 seconds for the same file and still produced a bigger one. That single result decides most of what follows. gzip and zip still matter for compatibility and xz still earns its place on ratio, but zstd is the tool you should reach for first.
This guide covers zip, gzip, bzip2, xz and zstd on Linux, plus the parallel versions (pigz, pbzip2, lbzip2) and the tar flags that tie them together. We measured ratio, compress and decompress time and peak memory on two real datasets, then broke each tool on purpose to capture the errors you will actually hit. The benchmark and walkthrough ran on Ubuntu 26.04 LTS (gzip 1.14, xz 5.8.3, zstd 1.5.7) in November 2026, and the installs and error cases were reproduced on Ubuntu 24.04 LTS and Rocky Linux 10.
Pick the right compressor for the job
Use zstd for anything you control on both ends: backups, log archives, container layers, data you move between your own servers. Use xz when the file is written once and downloaded many times, because the extra minutes of compression buy you the smallest file. Keep gzip and zip for the cases where the other side decides the format.
| Situation | Use | Why |
|---|---|---|
| Backups, database dumps, data in transit | zstd -3 -T0 | Smaller than gzip on source code in a fraction of the time |
| Log archives | zstd -9 -T0 | Beats every gzip level on logs in under 3 seconds per 700 MB |
| Release tarballs, ISO images, packages | xz -6 | Near-top ratio in half the time zstd -19 needs |
| Files for Windows or macOS users | zip | Opens natively everywhere with no extra software |
| HTTP, older scripts, anything that expects .gz | gzip or pigz | Universal decoder; pigz output is plain gzip |
| Existing .bz2 pipelines | lbzip2 | Same format, uses every core |
bzip2 doesn’t appear as a first choice anywhere in that table. On our numbers it lost to xz on ratio and to zstd on speed in both datasets, so the only reason to produce new .bz2 files is a consumer that can’t read anything else. Even lbzip2 doesn’t change that, because it runs the same algorithm faster without improving the ratio (8.64 against 10.36 for xz on the kernel tar).
Compare the benchmark results
The test box was a Google Cloud c3-standard-8 (8 vCPU, 32 GB RAM) on Ubuntu 26.04 LTS. Both inputs sat on tmpfs so disk speed did not skew the timings, and every tool except zip read stdin and wrote stdout. Each configuration ran once, timed with /usr/bin/time -f "%e %M" for wall seconds and peak resident memory, and every round trip was checked against the original SHA-256.
The two inputs pull in opposite directions. The kernel dataset is linux-7.3.6.tar from kernel.org, 1,719,797,760 bytes of mixed source code. The log dataset is BGL.log from the Loghub collection, 743,185,031 bytes of repetitive supercomputer logs that every tool squeezes hard.
Kernel source tar (1.7 GB)
| Command | Ratio | Compress (s) | Decompress (s) | Peak RAM compress | Peak RAM decompress |
|---|---|---|---|---|---|
zip -6 | 6.37 | 40.42 | 9.49 | 2.4 MB | 2.9 MB |
gzip -6 | 6.37 | 35.69 | 4.09 | 2.1 MB | 1.9 MB |
gzip -9 | 6.49 | 77.13 | 4.01 | 2.1 MB | 1.9 MB |
pigz -6 | 6.37 | 6.04 | 3.97 | 7.4 MB | 2.2 MB |
bzip2 -9 | 8.70 | 117.20 | 32.89 | 8.5 MB | 4.9 MB |
lbzip2 -9 | 8.64 | 12.12 | 4.34 | 58 MB | 55 MB |
xz -6 | 10.36 | 96.14 | 1.59 | 990 MB | 490 MB |
xz -6 -T1 | 10.54 | 522.90 | 7.33 | 95 MB | 10 MB |
xz -9e -T0 | 11.19 | 269.19 | 2.24 | 5329 MB | 2188 MB |
zstd -3 -T1 | 7.07 | 4.95 | 1.46 | 40 MB | 7.0 MB |
zstd -3 -T0 | 7.07 | 1.45 | 1.46 | 77 MB | 7.0 MB |
zstd -9 -T0 | 8.58 | 6.34 | 1.36 | 175 MB | 9.3 MB |
zstd -12 -T0 | 8.78 | 12.54 | 1.36 | 296 MB | 9.6 MB |
zstd -19 -T1 | 10.26 | 786.76 | 1.43 | 219 MB | 13 MB |
zstd -19 -T0 | 10.26 | 207.99 | 1.40 | 583 MB | 13 MB |
zstd -19 --long=27 -T0 | 10.62 | 204.42 | 1.59 | 915 MB | 134 MB |
Read the kernel table by pairs, because each pair answers a real question. zstd at level 3 beat gzip on both size and time, and with -T0 it finished in 1.45 seconds. At level 9 it matched bzip2 on ratio (8.58 against 8.70) in 6.34 seconds instead of 117.20. At the top end, though, xz took the crown: xz -6 reached 10.36 in 96.14 seconds, while zstd -19 -T0 needed 207.99 seconds to land slightly lower. Somewhere above level 12, zstd stops being the efficient choice, and xz gets you the same ratio in half the time.
Log corpus (743 MB)
| Command | Ratio | Compress (s) | Decompress (s) | Peak RAM compress | Peak RAM decompress |
|---|---|---|---|---|---|
zip -6 | 11.81 | 11.46 | 3.32 | 2.6 MB | 2.9 MB |
gzip -6 | 11.81 | 9.37 | 1.02 | 2.1 MB | 1.9 MB |
gzip -9 | 12.94 | 38.55 | 0.98 | 2.1 MB | 1.9 MB |
pigz -6 | 11.82 | 1.74 | 0.93 | 6.6 MB | 2.1 MB |
bzip2 -9 | 15.46 | 60.32 | 11.10 | 7.8 MB | 4.9 MB |
lbzip2 -9 | 15.48 | 5.34 | 1.57 | 59 MB | 66 MB |
xz -6 | 22.29 | 41.88 | 0.59 | 957 MB | 449 MB |
xz -6 -T1 | 22.50 | 198.03 | 2.56 | 95 MB | 10 MB |
xz -9e -T0 | 26.16 | 247.63 | 1.03 | 3282 MB | 974 MB |
zstd -3 -T1 | 10.59 | 1.47 | 0.61 | 38 MB | 6.9 MB |
zstd -3 -T0 | 10.59 | 0.46 | 0.61 | 71 MB | 7.1 MB |
zstd -9 -T0 | 14.05 | 2.37 | 0.46 | 166 MB | 9.2 MB |
zstd -12 -T0 | 14.21 | 4.71 | 0.45 | 287 MB | 9.3 MB |
zstd -19 -T1 | 21.70 | 438.45 | 0.40 | 215 MB | 13 MB |
zstd -19 -T0 | 21.70 | 120.47 | 0.40 | 560 MB | 13 MB |
zstd -19 --long=27 -T0 | 22.17 | 140.53 | 0.47 | 893 MB | 133 MB |
Logs changed one result, and it matters if you archive logs. Default zstd came out about 11% larger than gzip -6 here (ratio 10.59 against 11.81), so on this kind of data the zstd default trades size for speed. Raise zstd to level 9 and it jumps past every gzip setting to 14.05 in 2.37 seconds, so for log archives use zstd -9 -T0 rather than the default. xz again won the high end with 22.29 at 41.88 seconds, and xz -9e squeezed out 26.16 if you can afford the memory.
Plotting the kernel results as ratio against compress time makes the trade visible. The best options sit toward the top left, and the chart shows zstd owning the fast half while xz owns the top:


The memory columns hide the biggest surprise. Since the 5.6 line, xz runs multithreaded by default, as the xz release notes record. That is why plain xz -6 used 990 MB on the kernel tar while xz -6 -T1 used 95 MB and took 522.90 seconds instead of 96.14. Threaded mode also splits the output into blocks, which costs a little ratio (10.36 against 10.54) but lets decompression run in parallel. Watch xz -9e -T0 in particular: it peaked at 5329 MB to compress and 2188 MB to decompress, enough to push a small VM into the OOM killer. On a memory-tight box, pin -T1 or set --memlimit-compress.
Absolute seconds will move with your CPU, but the broad ordering held on both datasets, and that ordering is what you should base a default on. Still, time a sample of your own data before you change a fleet-wide default, because the log corpus already flipped one result here. A few minutes of /usr/bin/time runs is cheaper than recompressing a year of archives.
Install the compression tools
Don’t assume a fresh server has all five. The Ubuntu 24.04 cloud image we started from had gzip, xz and zstd but no bzip2, zip, unzip or pigz. Rocky Linux 10 shipped gzip, xz and pigz, and was missing bzip2, zstd, zip and unzip. On Ubuntu or Debian, install everything in one go:
sudo apt update
sudo apt install -y gzip bzip2 xz-utils zstd zip unzip pigz pbzip2 lbzip2
On Rocky Linux and AlmaLinux 10, the core tools come from BaseOS and pbzip2 from AppStream. lbzip2 lives in EPEL, so enable that repository first:
sudo dnf install -y zip unzip zstd bzip2 xz pigz
sudo dnf install -y epel-release
sudo dnf install -y pbzip2 lbzip2
Confirm what you ended up with. The last line is worth a look because the help text is wrong. It claims a default of one thread, but current zstd picks between 1 and 4 workers from the logical core count, and our 8 vCPU box used 2. That is why the benchmark passes -T1 or -T0 on every zstd run, and your scripts should do the same so results don’t change from one machine to the next.
gzip --version | head -1
xz --version | head -1
zstd --version
zip -v | sed -n 2p
zstd -H | grep -A1 -- '-T#'
Here is the full version check from the Ubuntu 26.04 benchmark machine, including the parallel tools and tar:

To see how many workers zstd really starts, compress a throwaway file in verbose mode. On the same machine it reported two:
seq 1 3000000 > t.log
zstd -vvvv -f t.log 2>&1 | grep -i thread
The first line of the output is the one that matters:
Compressing with 2 worker threads
--format=.zst --no-sparse --block-size=0 --memory=134217728 --threads=2 --content-size
Ubuntu 24.04 and Rocky Linux 10 ship older xz and zstd builds than 26.04, and the flags used here have been stable across those releases, so the commands carry over to scripts that target any of them. The one behaviour that differs is xz threading: the Ubuntu 24.04 xz still compresses on one thread by default, while the newer xz on Rocky Linux 10 and Ubuntu 26.04 runs multithreaded, as the benchmark notes above explain.
Create and test zip archives
zip is both an archiver and a compressor, so it takes a whole directory without tar. For the demos below we extracted the kernel/ directory of the kernel tree as src (17 MB, 793 files) and cut the first 50 MB of the log corpus into app.log. Compress the directory at the highest level and keep the paths with -r:
zip -9 -r -q src.zip src
Test the archive before you trust it, then list it to check the file count:
zip -T src.zip
unzip -l src.zip | tail -1
To extract into a different directory, pass -d. Comparing the restored tree with diff -r is the cheapest proof that nothing was lost:
unzip -q src.zip -d restore
diff -r src restore/src && echo identical
The 17 MB tree came out as a 4.3 MB zip, and zip -T reported test of src.zip OK:

zip compresses each file on its own, which is why it lost to every tar-based format on the same tree later in this guide. That design is also what lets you pull a single file out of a large zip instantly, so it is a fair trade for archives people browse rather than restore in full. Use zip when a person opens the archive by hand, and tar with a stream compressor when a machine restores it.
Compress single files with gzip, bzip2 and xz
These three compress one file at a time and replace the original unless you pass -k. All three take numeric levels up to 9 and the same -d to decompress and -t to test, so once you know one you know them all:
gzip -9 -k app.log
gzip -l app.log.gz
bzip2 -9 -k app.log
xz -vv -6 -k app.log
xz -l app.log.xz
Check each result with its own test flag. Each prints nothing on success, so chain an echo if you want confirmation in a script log:
gzip -t app.log.gz && echo "gzip test passed"
bzip2 -t app.log.bz2 && echo "bzip2 test passed"
xz -t app.log.xz && echo "xz test passed"
Read the xz -vv lines closely. On Ubuntu 26.04 it printed Using up to 8 threads and needed 1321 MiB to compress a 50 MB file, with no -T flag on the command line:

From the same 50 MB log, gzip produced 3,925,233 bytes, bzip2 3,347,907 and xz 2,175,096. The xz file is also split into three blocks, which is what threaded mode does and what lets it decompress in parallel. Every xz decoder reads multi-block files, so this is safe to share. Add -T1 when you want output identical to single-threaded xz (reproducible builds), a slightly better ratio, or less memory on small VMs, because that 1321 MiB comes on top of whatever else the box is running.
Use zstd for speed and ratio
zstd keeps the source file by default, unlike gzip, and prints a one-line summary for each file. Levels run from 1 to 19, and --ultra unlocks 20 to 22. The default is 3, which is where most of the speed in the benchmark came from:
zstd app.log
zstd -19 -T0 app.log -o app.log.19.zst
zstd --ultra -22 app.log -o app.log.22.zst
zstd -l app.log.zst app.log.19.zst app.log.22.zst
Test and decompress work the same way as gzip. unzstd is just zstd -d under another name:
zstd -t app.log.22.zst
unzstd app.log.zst -o restored.log
cmp app.log restored.log && echo identical
Level 19 halved the default output (4.42 MiB down to 2.22 MiB), while level 22 saved only another 0.02 MiB on top of that. That curve is typical, so treat --ultra as a last resort for files you publish, not a setting for backups. The zstd manual also warns that levels 20 and up need more memory to decompress, which lands on every reader of the file:

Three flags are worth knowing beyond levels:
-T0uses all physical cores (3.4x faster at level 3 on the kernel tar)--rsyncablekeeps output friendly to delta transfers--long=27finds repeats far apart, with no decoder flag needed
The rsyncable option matters when you ship compressed dumps with the rsync command, because a small change in the input no longer rewrites the whole compressed file, so only the changed blocks travel. The zstd manual lists the rest.
Combine tar with each compressor
gzip, bzip2, xz and zstd compress a single stream, so directories go through tar first. GNU tar has a short flag for each, and -I lets you pass any compressor with its own options. If you need a refresher on the rest of tar and file handling, our Linux commands cheat sheet covers it.
| Format | Create | Extension |
|---|---|---|
| gzip | tar -czf | .tar.gz, .tgz |
| bzip2 | tar -cjf | .tar.bz2 |
| xz | tar -cJf | .tar.xz |
| zstd | tar --zstd -cf | .tar.zst |
| Pick by suffix | tar -caf | any of the above |
| Custom options | tar -I 'zstd -19 -T0' -cf | .tar.zst |
Build one archive in each format from the same src tree so the sizes are comparable:
tar -czf src.tar.gz src
tar -cjf src.tar.bz2 src
tar -cJf src.tar.xz src
tar --zstd -cf src.tar.zst src
tar -I 'zstd -19 -T0' -cf src-19.tar.zst src
Extraction needs no format flag at all. GNU tar reads the magic bytes and calls the right decompressor, so tar -xf works on every file above:
tar -tzf src.tar.gz | head -3
mkdir -p x && tar -xf src-19.tar.zst -C x
diff -r src x/src && echo identical
On this small tree xz edged out zstd level 19 (2,972,572 against 3,012,214 bytes), and the default zstd landed next to gzip. The zip from the earlier section was the largest file in the listing:

Small inputs flatten the differences, which is why the 1.7 GB benchmark is the better guide for real backups.
Use every core with pigz, pbzip2 and lbzip2
gzip and bzip2 use a single core no matter how many you have. pigz, pbzip2 and lbzip2 split the input into chunks and compress them in parallel, and the output stays in the standard format, so any gzip or bzip2 can read it:
pigz -6 -c app.log > app-pigz.gz
pbzip2 -9 -p8 -c app.log > app-pbzip2.bz2
lbzip2 -9 -n 8 -c app.log > app-lbzip2.bz2
Inside tar, hand the parallel tool to -I. Testing the result with plain gzip proves the format did not change:
tar -I pigz -cf src-pigz.tar.gz src
gzip -t src-pigz.tar.gz && echo "standard gzip reads it"
We timed each one with the bash time keyword. pigz cut the 50 MB log from 0.594 to 0.141 seconds, and lbzip2 finished in half the time pbzip2 took while burning less than half the CPU (2.857 against 6.009 seconds of user time):

The full benchmark shows the same pattern on the big file. pigz compressed the kernel tar in 6.04 seconds where gzip took 35.69, and lbzip2 took bzip2 from 117.20 down to 12.12. The output sizes barely moved, because both tools run the same algorithm on smaller chunks. So if a .gz or .bz2 is a hard requirement, these are free speed. If it is not, look at zstd. On the kernel tar zstd -3 -T0 beat pigz on both time and size, while on logs it took level 9 to win on size (2.37 against 1.74 seconds). On the same kernel tar, level 12 matched the lbzip2 ratio at similar speed while decompressing about three times faster. On logs lbzip2 kept a clear ratio lead (15.48 against 14.21), so test before you migrate a .bz2 pipeline.
Fix common compression errors
Each error below was reproduced on the lab machines, so the messages match what you will see on a current Ubuntu or Rocky Linux system. Each heading quotes the error line the tool prints, because that is what you will paste into a search box when it happens.
tar: project.tar.gz: Cannot stat: No such file or directory
This comes from flag order. -f takes the next word as the archive name, so in tar -cfz project.tar.gz project tar writes an uncompressed archive called z and then tries to add project.tar.gz as an input file:
tar -cfz project.tar.gz project
Keep f last in the bundle, immediately before the file name. A related trap: the extension doesn’t choose the compressor unless you use -a, so tar -czf project.tar.zst quietly writes gzip data with a misleading name:
rm -f z
tar -czf project.tar.gz project
tar -czf project.tar.zst project && file project.tar.zst
tar -caf project.tar.zst project && file project.tar.zst
The capture from Ubuntu 24.04 shows the stray 645,120-byte z file and the file output for both versions of the .zst archive:

A stray one-letter file next to your archive is the sign of this bug, because tar used the compression letter as the archive name. Delete it and fix the flag order, so the next run writes the compressed archive you expected.
/bin/sh: line 1: zstd: command not found
GNU tar doesn’t link the compressors in; it runs them as child processes. On a default Rocky Linux 10 install, tar --zstd fails with tar: Child returned status 127 because the zstd binary isn’t there:

Install the missing package (sudo dnf install -y zstd here) and rerun. Expect the same class of failure with -j on Ubuntu cloud images, which ship without bzip2, although the wording differs because Ubuntu’s /bin/sh is dash.
Decoding error (36) : Frame requires too much memory for decoding
The normal zstd window is too small to see repeats that sit hundreds of megabytes apart. --long widens it. We built a 1 GB test file from the same 512 MB of random data twice, and --long=30 shrank it to 513 MB where the default produced 1.1 GB. The catch is on the other end:
zstd -q -T0 -3 --long=30 twice.bin -o twice-long.zst
zstd -d twice-long.zst -c > /dev/null
Decompression stops with Window size larger than maximum : 1073741824 > 134217728, because the decoder refuses windows over 128 MiB unless you allow them. zstd even prints the fix:

Pass the same --long value (or --memory=1024MB) when you decompress. Anything above --long=27 needs this, so record the flag next to the archive or nobody else will be able to open it.
zstd -d --long=30 twice-long.zst -c > /dev/null && echo "decompressed OK"
The kernel benchmark ran --long=27, which the zstd manual lists as the largest window a decoder accepts without a flag, and it still bought a small gain over plain level 19 (10.62 against 10.26). It cost memory, though: 915 MB to compress and 134 MB to decompress, so leave it off on small machines.
zip error: Entry too big to split, read, or write
The classic zip format stores sizes in 32 bits, which caps an entry at 4 GiB. Info-ZIP zip switches to the Zip64 extension automatically when a file needs it, so a plain zip of a 5 GB log works. On Linux you hit this error when Zip64 is turned off with -fz-:
zip -q -fz- big-nozip64.zip big.log
zip -q big.zip big.log
zipinfo -v big.zip | grep -i 'minimum software'
The working archive lists 5,368,709,120 bytes and asks for version 4.5 to extract, which is Zip64. gzip handled the same file without complaint. Its trailer only keeps the size modulo 2^32, though, so file reported 1 GiB and gzip -l spent 26.6 seconds decoding the stream to get the true size:

If an old Windows tool or embedded device can’t open a large zip, it lacks Zip64 support, and the fix is on that side or a split archive. Streamed input (cat big.log | zip stream.zip -) gets Zip64 by default because zip can’t know the size in advance, per the zip man page.
Set a default and stop thinking about it
For logs, the same answer applies whether you rotate them yourself or let logrotate do it: our guide to truncating log files and setting up logrotate shows where the compress and delaycompress options go. Backup tools have already made the call too: the BorgBackup with Borgmatic setup runs its archives with zstd. Compression shrinks what you store, but it is not protection, so pair it with the copies described in our immutable backups with Restic, Borg and S3 Object Lock guide.
These are the defaults we now put in scripts:
zstd -T0at the default level for backups and dumpszstd -9 -T0for log archivesxz -6for published tarballs, with-T1on small machines- zip or gzip for files other people open
After two datasets and three distributions, our verdict is simple. Make zstd -T0 your everyday compressor, at the default level for backups and level 9 for logs, and keep xz for files you publish. Treat gzip, zip and bzip2 as compatibility formats you produce only when the receiver asks for them. Test every archive you write with its -t flag, because a backup you never decompressed is only a guess.
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`
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?