zstd and 7-Zip on Linux: Fast Modern Compression Explained

zstd and 7-Zip on Linux: Fast Modern Compression Explained

For years, compression on Linux meant choosing between gzip (fast, mediocre ratio) and xz (small files, slow). Our guides to gzip, bzip2, and xz cover those. Then zstd arrived and made that trade-off largely unnecessary. This guide covers zstd in practice, and the other modern format you will meet: 7-Zip.

Why zstd took over

Zstandard (zstd) was developed at Facebook by Yann Collet and released in 2016. Its key property is a wide range of levels that are all fast to decompress:

CompressorRatioCompress speedDecompress speed
gzip -6ModerateModerateFast
xz -6HighSlowModerate
zstd -3 (default)Better than gzipVery fastVery fast
zstd -19Close to xzSlowVery fast

That combination is why zstd now sits underneath much of a modern Linux system:

  • Arch Linux packages (.pkg.tar.zst) and Fedora RPMs
  • Btrfs transparent compression (compress=zstd)
  • Kernel and initramfs compression on many distributions
  • zram swap compression, covered in zswap vs zram

Basic zstd usage

zstd file.log                 # creates file.log.zst, keeps the original
zstd -d file.log.zst          # decompress (or: unzstd)
zstd --rm file.log            # remove the original after compressing
zstdcat file.log.zst | less   # read without decompressing to disk

Unlike gzip, zstd keeps the original file by default.

Levels and threads

zstd -1 big.img               # fastest
zstd -19 big.img              # high compression
zstd --ultra -22 big.img      # maximum; needs lots of memory
zstd -T0 -19 big.img          # use all CPU cores

-T0 multithreading makes high levels practical on large files. Note that memory use rises sharply at high levels, both when compressing and, for --ultra, when decompressing.

Long-range mode

For large files with repetition far apart, such as VM images, database dumps, and backups, long-range matching finds matches across a much bigger window:

zstd --long=27 -T0 -19 vm-disk.img
zstd -d --long=27 vm-disk.img.zst     # decompression needs the same flag

tar with zstd

tar --zstd -cf backup.tar.zst ~/projects        # create
tar -xf backup.tar.zst                          # extract (tar detects zstd)
tar -I 'zstd -19 -T0' -cf backup.tar.zst ~/projects   # with options

tar preserves Unix permissions, ownership, symlinks, and timestamps, which is why it remains the right container for Linux backups. Our tar guide covers the rest, and the tar command builder generates the flags.

Dictionaries

For many small, similar files, such as JSON records or log lines, zstd can train a dictionary that dramatically improves the ratio:

zstd --train samples/* -o records.dict
zstd -D records.dict record.json

7-Zip on Linux

7-Zip is the archiver Windows users know, with its own .7z format based on LZMA2, which compresses very well.

There are two commands you may find:

CommandSource
7zzOfficial 7-Zip for Linux from Igor Pavlov, since 2021
7zUsually p7zip, an older unofficial port that went unmaintained for years

Prefer the official one, packaged as 7zip on most current distributions:

sudo apt install 7zip        # provides 7zz (Debian 12+, Ubuntu 23.04+)
sudo dnf install 7zip
sudo pacman -S 7zip

Using it

7zz a archive.7z ~/documents            # add (create)
7zz x archive.7z                        # extract with paths
7zz l archive.7z                        # list
7zz a -mx=9 archive.7z files/           # maximum compression
7zz a -p -mhe=on secret.7z files/       # AES-256 encryption, hide file names

-mhe=on encrypts the headers too, so nobody can see the file names without the password; plain encrypted ZIP files expose them.

7-Zip also extracts a long list of other formats, including RAR, ISO, CAB, WIM, and DMG, which makes it a handy universal extractor.

When not to use .7z

.7z does not store Unix ownership and permissions properly. For backing up Linux files, compress a tar archive instead:

tar -cf - ~/projects | 7zz a -si projects.tar.7z

or simply use tar --zstd.

Which to use?

SituationUse
General compression on Linuxzstd (default level)
Backups and file transfers between Linux systemstar --zstd
Archives downloaded many times, size matters mosttar with xz -9 or zstd -19 --long
Sharing with Windows users.zip (universal) or .7z
Encrypted archive that hides file names7zz a -p -mhe=on
Opening a RAR or other odd format7zz x

For files you send to others, zip and unzip remain the most universally readable option.

Frequently Asked Questions

What is zstd?

zstd, or Zstandard, is a compression algorithm and command-line tool developed at Facebook and released in 2016. It compresses about as well as gzip at its fastest settings while being much faster, and approaches xz at high levels, with very fast decompression at every level.

How do I create a tar.zst archive?

Use tar —zstd -cf archive.tar.zst directory, or tar -I zstd -cf archive.tar.zst directory with older tar versions. To pass options such as a compression level or threads, use tar -I “zstd -19 -T0” -cf archive.tar.zst directory. Extract with tar -xf archive.tar.zst.

Which zstd compression level should I use?

The default level 3 is a good general choice. Levels 1 and 2 are for speed, 10 to 19 for smaller files at the cost of compression time, and —ultra allows 20 to 22 for maximum compression with much higher memory use. Decompression speed stays fast whatever level was used.

Is zstd better than xz?

For most uses, yes, because it compresses and decompresses far faster with only slightly larger files. xz can still produce the smallest files at its highest settings, so it remains reasonable for archives that are compressed once and downloaded many times.

Should I use 7-Zip on Linux?

Use it when exchanging archives with Windows users, when you need AES-256 encrypted archives that also hide file names, or when you need to open .7z, .rar, and many other formats. For backups of Linux files, tar with zstd or xz is better because 7z does not preserve Unix ownership and permissions.

What is the difference between 7zz and 7z?

7zz is the official 7-Zip for Linux from the original author, available since 2021. The older 7z command usually comes from p7zip, an unofficial port that was unmaintained for years. Prefer 7zz, which most distributions now package as 7zip.