zstd — Fast Compression with Zstandard

Practical guide to zstd (Zstandard) — fast compression with an excellent speed-to-ratio balance, multi-threading and tar integration.

zstd (Zstandard) is a modern compression tool from Meta that strikes a remarkable balance between speed and compression ratio – at the default level 3 it compresses in near real time, while higher levels reach ratios on par with xz. On top of that come multi-threading, seamless tar integration and dictionary compression for many small files. This guide walks you through the commands you reach for daily, from quick compression to a streamed database backup.

Compress

zstd <file> — Compress a file (creates file.zst, keeps original).

zstd data.log

zstd -<level> <file> — Compress with a specific level (1=fastest, 19=best, default 3).

zstd -19 data.log

zstd --ultra -<level> <file> — Use ultra compression levels (20-22, very slow but smallest).

zstd --ultra -22 data.log

zstd -o <output> <file> — Compress to a specific output filename.

zstd -o backup.zst data.log

zstd --rm <file> — Compress and remove the original file.

zstd --rm data.log

zstd -T<n> <file> — Multi-threaded compression (0=auto-detect cores).

zstd -T0 -19 largefile.dat

Decompress

zstd -d <file>.zst — Decompress a file.

zstd -d data.log.zst

unzstd <file>.zst — Decompress (alias for zstd -d).

unzstd data.log.zst

zstd -d -o <output> <file>.zst — Decompress to a specific filename.

zstd -d -o restored.log data.log.zst

zstdcat <file>.zst — Decompress to stdout (like zcat for gzip).

zstdcat data.log.zst | grep 'error'

zstd -d --rm <file>.zst — Decompress and remove the compressed file.

zstd -d --rm data.log.zst

Piping & Streaming

<command> | zstd > <output>.zst — Compress piped data.

mysqldump mydb | zstd > backup.sql.zst

zstd -d < <input>.zst | <command> — Decompress and pipe to a command.

zstd -d < backup.sql.zst | mysql mydb

tar cf - <dir> | zstd > <archive>.tar.zst — Create a tar.zst archive (tar + zstd).

tar cf - project/ | zstd -T0 > project.tar.zst

zstd -d < <archive>.tar.zst | tar xf - — Extract a tar.zst archive.

zstd -d < project.tar.zst | tar xf -

tar --zstd -cf <archive>.tar.zst <dir> — Create tar.zst using tar's built-in zstd support (GNU tar).

tar --zstd -cf project.tar.zst project/

tar --zstd -xf <archive>.tar.zst — Extract tar.zst using tar's built-in support.

tar --zstd -xf project.tar.zst

Multiple Files

zstd <file1> <file2> <file3> — Compress multiple files individually.

zstd *.log

zstd -d *.zst — Decompress multiple files.

zstd -d *.zst

zstd -r <dir> — Recursively compress all files in a directory.

zstd -r /var/log/old/

Info & Testing

zstd -l <file>.zst — Show compression info (ratio, sizes).

zstd -l data.log.zst

zstd -t <file>.zst — Test integrity of a compressed file.

zstd -t backup.sql.zst

zstd -b <file> — Benchmark compression/decompression speed.

zstd -b data.log

zstd -b -e<level> <file> — Benchmark across compression levels.

zstd -b1 -e19 data.log

zstd -V — Show the zstd version.

zstd -V

Conclusion

zstd is the obvious choice today when you want speed and compression ratio at the same time: the default level 3 is blazing fast, -T0 scales across all cores, and tar --zstd makes archiving convenient. Keep two things in mind: --rm deletes the original irreversibly – only use it once the compressed file has safely arrived. And the ultra levels --ultra -20 through -22 need significantly more memory not just when compressing but also when decompressing – so use them with care on tightly provisioned target systems.

Further Reading

  • 7z – high-ratio archive format with strong LZMA compression
  • gzip – classic, widely supported compressor (DEFLATE)
  • tar – bundles files into an archive, often paired with zstd