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.logzstd -<level> <file> — Compress with a specific level (1=fastest, 19=best, default 3).
zstd -19 data.logzstd --ultra -<level> <file> — Use ultra compression levels (20-22, very slow but smallest).
zstd --ultra -22 data.logzstd -o <output> <file> — Compress to a specific output filename.
zstd -o backup.zst data.logzstd --rm <file> — Compress and remove the original file.
zstd --rm data.logzstd -T<n> <file> — Multi-threaded compression (0=auto-detect cores).
zstd -T0 -19 largefile.datDecompress
zstd -d <file>.zst — Decompress a file.
zstd -d data.log.zstunzstd <file>.zst — Decompress (alias for zstd -d).
unzstd data.log.zstzstd -d -o <output> <file>.zst — Decompress to a specific filename.
zstd -d -o restored.log data.log.zstzstdcat <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.zstPiping & Streaming
<command> | zstd > <output>.zst — Compress piped data.
mysqldump mydb | zstd > backup.sql.zstzstd -d < <input>.zst | <command> — Decompress and pipe to a command.
zstd -d < backup.sql.zst | mysql mydbtar cf - <dir> | zstd > <archive>.tar.zst — Create a tar.zst archive (tar + zstd).
tar cf - project/ | zstd -T0 > project.tar.zstzstd -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.zstMultiple Files
zstd <file1> <file2> <file3> — Compress multiple files individually.
zstd *.logzstd -d *.zst — Decompress multiple files.
zstd -d *.zstzstd -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.zstzstd -t <file>.zst — Test integrity of a compressed file.
zstd -t backup.sql.zstzstd -b <file> — Benchmark compression/decompression speed.
zstd -b data.logzstd -b -e<level> <file> — Benchmark across compression levels.
zstd -b1 -e19 data.logzstd -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
- zstd – GitHub project – source code, releases and documentation
- Zstandard – official project site – format specification, benchmarks and manual