zstd
Overview
zstd (Zstandard) is a fast lossless compressor with excellent ratio/speed tradeoffs. It is often preferable to gzip for logs, backups, and package artifacts.
Syntax
zstd [options] [file...]
zstd -d [options] [file...]
zstdmt [options] [file...] # multi-threaded alias/common packagingCommon Options
| Option | Description |
|---|---|
-# |
Compression level 1–19 (default 3); ultra up to 22 with –ultra |
-d / --decompress |
Decompress |
-c / --stdout |
Write to stdout |
-f |
Overwrite output |
-t |
Test integrity |
-T# |
Threads (0 = all CPUs) |
-o file |
Output path |
--rm |
Remove source after success |
-v |
Verbose |
Key Use Cases
- Compress backups and tarballs
- Replace gzip for large log archives
- Stream compress in pipelines
- Multi-threaded bulk compression
Examples with Explanations
Compress a file
zstd big.log
# creates big.log.zst, keeps original unless --rmDefault level balances speed and size.
Decompress
zstd -d big.log.zstRestores big.log beside the archive.
Tar + zstd (modern tar)
tar --zstd -cf project.tar.zst project/
tar --zstd -tf project.tar.zst
tar --zstd -xf project.tar.zstGNU tar 1.31+ supports --zstd natively.
Pipeline
tar -cf - mydir | zstd -T0 -19 -o mydir.tar.zstHigh ratio with all cores; stream avoids temp tar.
Decompress to stdout
zstd -dc data.json.zst | jq .Chain into JSON tools without unpacking to disk.
Notes & Pitfalls
- Prefer
.zstextension; tools recognize it widely now. - Level 19 is slow but dense; level 3 is a good default for logs.
- Package:
sudo apt install zstd.