LinuxCommandLibrary

zstd

Compress or decompress files using the Zstandard algorithm

TLDR

Compress a file into a new file with the .zst suffix

$ zstd [path/to/file]
copy

Decompress a file
$ zstd --decompress [path/to/file.zst]
copy

Decompress to stdout
$ zstd --decompress --stdout [path/to/file.zst]
copy

Compress a file specifying the compression level, where 1=fastest, 19=slowest and 3=default
$ zstd -[level] [path/to/file]
copy

Unlock higher compression levels (up to 22) using more memory (both for compression and decompression)
$ zstd --ultra -[level] [path/to/file]
copy

SYNOPSIS

zstd [options] [input_file]

PARAMETERS

-d, --decompress
    Decompress the input file.

-z, --compress
    Compress the input file (default).

-f, --force
    Overwrite existing output files without prompting.

-o file
    Specify the output file name. If not specified, the output filename will be derived from the input filename.

-l, --list
    Display information about the compressed file (original size, compressed size, compression ratio).

-v, --verbose
    Provide more detailed output.

-q, --quiet
    Suppress all warnings; specify twice to suppress errors too.

-#
    Compression level (1-22, higher is slower and gives better compression). Default level is 3.

--train dictionary_file
    Train a dictionary on the provided file for better compression efficiency on similar data.

--fast[=#]
    Switch to ultra-fast compression levels.

--long[=#]
    Switch to stronger compression levels (can be slow).

DESCRIPTION

zstd is a fast lossless compression algorithm, providing high compression ratios while maintaining excellent speed.
It offers a wide range of compression levels, allowing users to trade off between compression speed and size. The zstd command-line tool is used to compress and decompress files, and it supports various options for controlling the compression level, dictionary usage, and other parameters.
It aims to provide a modern alternative to traditional compression algorithms like gzip and bzip2, offering better performance in many scenarios. zstd is widely used for data storage, archival, and network transmission, where efficient compression is critical.
It's designed for both single-threaded and multi-threaded operation, improving utilization of modern CPU cores. The tool also includes integrity checks to ensure data correctness after compression and decompression.

CAVEATS

Decompression requires the complete compressed file. Corruption during compression or storage can lead to irreversible data loss. Using very high compression levels may significantly increase compression time and memory usage.

DICTIONARIES

zstd supports dictionaries for improved compression, particularly on small files or repetitive data.
A dictionary can be created using the zstd command with the --train option and then used for compression and decompression using the --use-dictionary option.
The same dictionary file is needed for decompression.

HISTORY

zstd was developed by Facebook and initially released in 2015.
It was designed to be a modern, high-performance compression algorithm suitable for a wide range of applications.
Its open-source nature and good performance have led to its adoption in various projects, including Linux distributions, databases, and archiving tools.
Continued development focuses on improving compression ratios, speed, and feature set.

SEE ALSO

gzip(1), bzip2(1), xz(1), tar(1)

Copied to clipboard