Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Archives and Compression

Linux zstd command

Reference for the Linux zstd command: fast Zstandard compression with levels 1-19 and --ultra, threads with -T0, dictionaries, long-distance mode, tar --zstd and streaming.

zstd is the command-line tool for Zstandard, a compression algorithm designed at Facebook (now Meta) that is very fast and offers a wide range of speed/size trade-offs. At its default level it compresses faster than gzip and produces smaller files; at high levels it approaches xz ratios while decompressing much faster.

That combination made it the default for package formats (Arch Linux, Fedora's RPMs), filesystem compression (Btrfs, ZFS), backups and container layers. Files end in .zst, and unzstd, zstdcat and zstd -d decompress them.

Terminal
zstd data.csv           # data.csv.zst, original kept
zstd -d data.csv.zst

Try it

The sandbox image does not include zstd, so the commands below are read-only. The runnable example only prepares data and compares sizes with the tools that are present, which shows why people switch to zstd on a real machine.

Bash Prepare data and baseline with gzip and xz

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash A tar plus compressor pipeline that works with any filter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
zstd [OPTION]... [FILE]...
zstd -d [OPTION]... FILE.zst
zstdcat FILE.zst
Option Description
-1 ... -19 Compression level; default 3. Higher means smaller and slower.
--fast[=N] Negative levels: even faster, lower ratio.
--ultra -20 ... -22 Levels above 19; need much more memory.
-d, --decompress Decompress.
-k / --rm Keep (default) / remove the source file after success.
-c, --stdout Write to standard output.
-o FILE Write output to this file.
-T N Use N threads; -T0 uses all cores.
--long[=N] Long-distance matching with a window of 2^N bytes, good for huge, repetitive files.
-D DICT Use a dictionary; create one with --train FILES.
-t, --test Check integrity.
-l, --list Show information about .zst files.
-r Recurse into directories.
-f Overwrite and process links.
-q / -v Quiet / verbose.

Returns: 0 on success, non-zero on errors such as corrupt input, unreadable files or an existing output file without -f.

Usage notes

  • The source is kept by default, unlike gzip, bzip2 and xz. Use --rm to delete it after a successful compression.
  • GNU tar integration. tar --zstd -cf out.tar.zst dir and tar -xf out.tar.zst (tar detects it) work with tar 1.31 or later; older tar needs tar -I zstd. For levels or threads, pass options: tar -I 'zstd -T0 -10' -cf out.tar.zst dir.
  • Level guide. 1-3: very fast, good for logs and network streams. 6-10: balanced for builds. 15-19: for data compressed once and read many times. Above 19 only for archives where memory and time do not matter.
  • Decompression speed is nearly constant across levels and several times faster than xz, which is the main attraction for software distribution.
  • Dictionaries greatly improve compression of many small, similar files (JSON records, small messages): zstd --train samples/* -o dict then zstd -D dict file. The same dictionary is required to decompress.
  • Memory. Decompression needs a window as big as was used for compression; --memory= / --long windows above 128 MB require the matching flag when decompressing.
  • Adaptive mode --adapt changes the level on the fly depending on whether the output pipe is the bottleneck.
  • Multi-threaded output is compatible, and the file can be decoded by any zstd implementation.
  • Not installed everywhere. On Debian/Ubuntu install the zstd package; on RHEL-family systems it is zstd as well. Keep gzip as the fallback when you must run on bare systems.