xref: /freebsd/sys/contrib/zstd/programs/zstd.1.md (revision e9b1dc32c9bd2ebae5f9e140bfa0e0321bc366b5)
1zstd(1) -- zstd, zstdmt, unzstd, zstdcat - Compress or decompress .zst files
2============================================================================
3
4SYNOPSIS
5--------
6
7`zstd` [*OPTIONS*] [-|_INPUT-FILE_] [-o _OUTPUT-FILE_]
8
9`zstdmt` is equivalent to `zstd -T0`
10
11`unzstd` is equivalent to `zstd -d`
12
13`zstdcat` is equivalent to `zstd -dcf`
14
15
16DESCRIPTION
17-----------
18`zstd` is a fast lossless compression algorithm and data compression tool,
19with command line syntax similar to `gzip (1)` and `xz (1)`.
20It is based on the **LZ77** family, with further FSE & huff0 entropy stages.
21`zstd` offers highly configurable compression speed,
22with fast modes at > 200 MB/s per core,
23and strong modes nearing lzma compression ratios.
24It also features a very fast decoder, with speeds > 500 MB/s per core.
25
26`zstd` command line syntax is generally similar to gzip,
27but features the following differences :
28
29  - Source files are preserved by default.
30    It's possible to remove them automatically by using the `--rm` command.
31  - When compressing a single file, `zstd` displays progress notifications
32    and result summary by default.
33    Use `-q` to turn them off.
34  - `zstd` does not accept input from console,
35    but it properly accepts `stdin` when it's not the console.
36  - `zstd` displays a short help page when command line is an error.
37    Use `-q` to turn it off.
38
39`zstd` compresses or decompresses each _file_ according to the selected
40operation mode.
41If no _files_ are given or _file_ is `-`, `zstd` reads from standard input
42and writes the processed data to standard output.
43`zstd` will refuse to write compressed data to standard output
44if it is a terminal : it will display an error message and skip the _file_.
45Similarly, `zstd` will refuse to read compressed data from standard input
46if it is a terminal.
47
48Unless `--stdout` or `-o` is specified, _files_ are written to a new file
49whose name is derived from the source _file_ name:
50
51* When compressing, the suffix `.zst` is appended to the source filename to
52  get the target filename.
53* When decompressing, the `.zst` suffix is removed from the source filename to
54  get the target filename
55
56### Concatenation with .zst files
57It is possible to concatenate `.zst` files as is.
58`zstd` will decompress such files as if they were a single `.zst` file.
59
60OPTIONS
61-------
62
63### Integer suffixes and special values
64In most places where an integer argument is expected,
65an optional suffix is supported to easily indicate large integers.
66There must be no space between the integer and the suffix.
67
68* `KiB`:
69    Multiply the integer by 1,024 (2\^10).
70    `Ki`, `K`, and `KB` are accepted as synonyms for `KiB`.
71* `MiB`:
72    Multiply the integer by 1,048,576 (2\^20).
73    `Mi`, `M`, and `MB` are accepted as synonyms for `MiB`.
74
75### Operation mode
76If multiple operation mode options are given,
77the last one takes effect.
78
79* `-z`, `--compress`:
80    Compress.
81    This is the default operation mode when no operation mode option is specified
82    and no other operation mode is implied from the command name
83    (for example, `unzstd` implies `--decompress`).
84* `-d`, `--decompress`, `--uncompress`:
85    Decompress.
86* `-t`, `--test`:
87    Test the integrity of compressed _files_.
88    This option is equivalent to `--decompress --stdout` except that the
89    decompressed data is discarded instead of being written to standard output.
90    No files are created or removed.
91* `-b#`:
92    Benchmark file(s) using compression level #
93* `--train FILEs`:
94    Use FILEs as a training set to create a dictionary.
95    The training set should contain a lot of small files (> 100).
96* `-l`, `--list`:
97    Display information related to a zstd compressed file, such as size, ratio, and checksum.
98    Some of these fields may not be available.
99    This command can be augmented with the `-v` modifier.
100
101### Operation modifiers
102
103* `-#`:
104    `#` compression level \[1-19] (default: 3)
105* `--fast[=#]`:
106    switch to ultra-fast compression levels.
107    If `=#` is not present, it defaults to `1`.
108    The higher the value, the faster the compression speed,
109    at the cost of some compression ratio.
110    This setting overwrites compression level if one was set previously.
111    Similarly, if a compression level is set after `--fast`, it overrides it.
112* `--ultra`:
113    unlocks high compression levels 20+ (maximum 22), using a lot more memory.
114    Note that decompression will also require more memory when using these levels.
115* `--long[=#]`:
116    enables long distance matching with `#` `windowLog`, if not `#` is not
117    present it defaults to `27`.
118    This increases the window size (`windowLog`) and memory usage for both the
119    compressor and decompressor.
120    This setting is designed to improve the compression ratio for files with
121    long matches at a large distance.
122
123    Note: If `windowLog` is set to larger than 27, `--long=windowLog` or
124    `--memory=windowSize` needs to be passed to the decompressor.
125* `-T#`, `--threads=#`:
126    Compress using `#` working threads (default: 1).
127    If `#` is 0, attempt to detect and use the number of physical CPU cores.
128    In all cases, the nb of threads is capped to ZSTDMT_NBTHREADS_MAX==200.
129    This modifier does nothing if `zstd` is compiled without multithread support.
130* `--single-thread`:
131    Does not spawn a thread for compression, use a single thread for both I/O and compression.
132    In this mode, compression is serialized with I/O, which is slightly slower.
133    (This is different from `-T1`, which spawns 1 compression thread in parallel of I/O).
134    This mode is the only one available when multithread support is disabled.
135    Single-thread mode features lower memory usage.
136    Final compressed result is slightly different from `-T1`.
137* `--adapt[=min=#,max=#]` :
138    `zstd` will dynamically adapt compression level to perceived I/O conditions.
139    Compression level adaptation can be observed live by using command `-v`.
140    Adaptation can be constrained between supplied `min` and `max` levels.
141    The feature works when combined with multi-threading and `--long` mode.
142    It does not work with `--single-thread`.
143    It sets window size to 8 MB by default (can be changed manually, see `wlog`).
144    Due to the chaotic nature of dynamic adaptation, compressed result is not reproducible.
145    _note_ : at the time of this writing, `--adapt` can remain stuck at low speed
146    when combined with multiple worker threads (>=2).
147* `-D file`:
148    use `file` as Dictionary to compress or decompress FILE(s)
149* `--no-dictID`:
150    do not store dictionary ID within frame header (dictionary compression).
151    The decoder will have to rely on implicit knowledge about which dictionary to use,
152    it won't be able to check if it's correct.
153* `-o file`:
154    save result into `file` (only possible with a single _INPUT-FILE_)
155* `-f`, `--force`:
156    overwrite output without prompting, and (de)compress symbolic links
157* `-c`, `--stdout`:
158    force write to standard output, even if it is the console
159* `--[no-]sparse`:
160    enable / disable sparse FS support,
161    to make files with many zeroes smaller on disk.
162    Creating sparse files may save disk space and speed up decompression by
163    reducing the amount of disk I/O.
164    default: enabled when output is into a file,
165    and disabled when output is stdout.
166    This setting overrides default and can force sparse mode over stdout.
167* `--rm`:
168    remove source file(s) after successful compression or decompression
169* `-k`, `--keep`:
170    keep source file(s) after successful compression or decompression.
171    This is the default behavior.
172* `-r`:
173    operate recursively on dictionaries
174* `--format=FORMAT`:
175    compress and decompress in other formats. If compiled with
176    support, zstd can compress to or decompress from other compression algorithm
177    formats. Possibly available options are `zstd`, `gzip`, `xz`, `lzma`, and `lz4`.
178    If no such format is provided, `zstd` is the default.
179* `-h`/`-H`, `--help`:
180    display help/long help and exit
181* `-V`, `--version`:
182    display version number and exit.
183    Advanced : `-vV` also displays supported formats.
184    `-vvV` also displays POSIX support.
185* `-v`:
186    verbose mode
187* `-q`, `--quiet`:
188    suppress warnings, interactivity, and notifications.
189    specify twice to suppress errors too.
190* `-C`, `--[no-]check`:
191    add integrity check computed from uncompressed data (default: enabled)
192* `--`:
193    All arguments after `--` are treated as files
194
195
196DICTIONARY BUILDER
197------------------
198`zstd` offers _dictionary_ compression,
199which greatly improves efficiency on small files and messages.
200It's possible to train `zstd` with a set of samples,
201the result of which is saved into a file called a `dictionary`.
202Then during compression and decompression, reference the same dictionary,
203using command `-D dictionaryFileName`.
204Compression of small files similar to the sample set will be greatly improved.
205
206* `--train FILEs`:
207    Use FILEs as training set to create a dictionary.
208    The training set should contain a lot of small files (> 100),
209    and weight typically 100x the target dictionary size
210    (for example, 10 MB for a 100 KB dictionary).
211
212    Supports multithreading if `zstd` is compiled with threading support.
213    Additional parameters can be specified with `--train-fastcover`.
214    The legacy dictionary builder can be accessed with `--train-legacy`.
215    The cover dictionary builder can be accessed with `--train-cover`.
216    Equivalent to `--train-fastcover=d=8,steps=4`.
217* `-o file`:
218    Dictionary saved into `file` (default name: dictionary).
219* `--maxdict=#`:
220    Limit dictionary to specified size (default: 112640).
221* `-#`:
222    Use `#` compression level during training (optional).
223    Will generate statistics more tuned for selected compression level,
224    resulting in a _small_ compression ratio improvement for this level.
225* `-B#`:
226    Split input files in blocks of size # (default: no split)
227* `--dictID=#`:
228    A dictionary ID is a locally unique ID that a decoder can use to verify it is
229    using the right dictionary.
230    By default, zstd will create a 4-bytes random number ID.
231    It's possible to give a precise number instead.
232    Short numbers have an advantage : an ID < 256 will only need 1 byte in the
233    compressed frame header, and an ID < 65536 will only need 2 bytes.
234    This compares favorably to 4 bytes default.
235    However, it's up to the dictionary manager to not assign twice the same ID to
236    2 different dictionaries.
237* `--train-cover[=k#,d=#,steps=#,split=#]`:
238    Select parameters for the default dictionary builder algorithm named cover.
239    If _d_ is not specified, then it tries _d_ = 6 and _d_ = 8.
240    If _k_ is not specified, then it tries _steps_ values in the range [50, 2000].
241    If _steps_ is not specified, then the default value of 40 is used.
242    If _split_ is not specified or split <= 0, then the default value of 100 is used.
243    Requires that _d_ <= _k_.
244
245    Selects segments of size _k_ with highest score to put in the dictionary.
246    The score of a segment is computed by the sum of the frequencies of all the
247    subsegments of size _d_.
248    Generally _d_ should be in the range [6, 8], occasionally up to 16, but the
249    algorithm will run faster with d <= _8_.
250    Good values for _k_ vary widely based on the input data, but a safe range is
251    [2 * _d_, 2000].
252    If _split_ is 100, all input samples are used for both training and testing
253    to find optimal _d_ and _k_ to build dictionary.
254    Supports multithreading if `zstd` is compiled with threading support.
255
256    Examples:
257
258    `zstd --train-cover FILEs`
259
260    `zstd --train-cover=k=50,d=8 FILEs`
261
262    `zstd --train-cover=d=8,steps=500 FILEs`
263
264    `zstd --train-cover=k=50 FILEs`
265
266    `zstd --train-cover=k=50,split=60 FILEs`
267
268* `--train-fastcover[=k#,d=#,f=#,steps=#,split=#,accel=#]`:
269    Same as cover but with extra parameters _f_ and _accel_ and different default value of split
270    If _split_ is not specified, then it tries _split_ = 75.
271    If _f_ is not specified, then it tries _f_ = 20.
272    Requires that 0 < _f_ < 32.
273    If _accel_ is not specified, then it tries _accel_ = 1.
274    Requires that 0 < _accel_ <= 10.
275    Requires that _d_ = 6 or _d_ = 8.
276
277    _f_ is log of size of array that keeps track of frequency of subsegments of size _d_.
278    The subsegment is hashed to an index in the range [0,2^_f_ - 1].
279    It is possible that 2 different subsegments are hashed to the same index, and they are considered as the same subsegment when computing frequency.
280    Using a higher _f_ reduces collision but takes longer.
281
282    Examples:
283
284    `zstd --train-fastcover FILEs`
285
286    `zstd --train-fastcover=d=8,f=15,accel=2 FILEs`
287
288* `--train-legacy[=selectivity=#]`:
289    Use legacy dictionary builder algorithm with the given dictionary
290    _selectivity_ (default: 9).
291    The smaller the _selectivity_ value, the denser the dictionary,
292    improving its efficiency but reducing its possible maximum size.
293    `--train-legacy=s=#` is also accepted.
294
295    Examples:
296
297    `zstd --train-legacy FILEs`
298
299    `zstd --train-legacy=selectivity=8 FILEs`
300
301
302BENCHMARK
303---------
304
305* `-b#`:
306    benchmark file(s) using compression level #
307* `-e#`:
308    benchmark file(s) using multiple compression levels, from `-b#` to `-e#` (inclusive)
309* `-i#`:
310    minimum evaluation time, in seconds (default: 3s), benchmark mode only
311* `-B#`, `--block-size=#`:
312    cut file(s) into independent blocks of size # (default: no block)
313* `--priority=rt`:
314    set process priority to real-time
315
316**Output Format:** CompressionLevel#Filename : IntputSize -> OutputSize (CompressionRatio), CompressionSpeed, DecompressionSpeed
317
318**Methodology:** For both compression and decompression speed, the entire input is compressed/decompressed in-memory to measure speed. A run lasts at least 1 sec, so when files are small, they are compressed/decompressed several times per run, in order to improve measurement accuracy.
319
320ADVANCED COMPRESSION OPTIONS
321----------------------------
322### --zstd[=options]:
323`zstd` provides 22 predefined compression levels.
324The selected or default predefined compression level can be changed with
325advanced compression options.
326The _options_ are provided as a comma-separated list.
327You may specify only the options you want to change and the rest will be
328taken from the selected or default compression level.
329The list of available _options_:
330
331- `strategy`=_strat_, `strat`=_strat_:
332    Specify a strategy used by a match finder.
333
334    There are 8 strategies numbered from 1 to 8, from faster to stronger:
335    1=ZSTD\_fast, 2=ZSTD\_dfast, 3=ZSTD\_greedy, 4=ZSTD\_lazy,
336    5=ZSTD\_lazy2, 6=ZSTD\_btlazy2, 7=ZSTD\_btopt, 8=ZSTD\_btultra.
337
338- `windowLog`=_wlog_, `wlog`=_wlog_:
339    Specify the maximum number of bits for a match distance.
340
341    The higher number of increases the chance to find a match which usually
342    improves compression ratio.
343    It also increases memory requirements for the compressor and decompressor.
344    The minimum _wlog_ is 10 (1 KiB) and the maximum is 30 (1 GiB) on 32-bit
345    platforms and 31 (2 GiB) on 64-bit platforms.
346
347    Note: If `windowLog` is set to larger than 27, `--long=windowLog` or
348    `--memory=windowSize` needs to be passed to the decompressor.
349
350- `hashLog`=_hlog_, `hlog`=_hlog_:
351    Specify the maximum number of bits for a hash table.
352
353    Bigger hash tables cause less collisions which usually makes compression
354    faster, but requires more memory during compression.
355
356    The minimum _hlog_ is 6 (64 B) and the maximum is 26 (128 MiB).
357
358- `chainLog`=_clog_, `clog`=_clog_:
359    Specify the maximum number of bits for a hash chain or a binary tree.
360
361    Higher numbers of bits increases the chance to find a match which usually
362    improves compression ratio.
363    It also slows down compression speed and increases memory requirements for
364    compression.
365    This option is ignored for the ZSTD_fast strategy.
366
367    The minimum _clog_ is 6 (64 B) and the maximum is 28 (256 MiB).
368
369- `searchLog`=_slog_, `slog`=_slog_:
370    Specify the maximum number of searches in a hash chain or a binary tree
371    using logarithmic scale.
372
373    More searches increases the chance to find a match which usually increases
374    compression ratio but decreases compression speed.
375
376    The minimum _slog_ is 1 and the maximum is 26.
377
378- `searchLength`=_slen_, `slen`=_slen_:
379    Specify the minimum searched length of a match in a hash table.
380
381    Larger search lengths usually decrease compression ratio but improve
382    decompression speed.
383
384    The minimum _slen_ is 3 and the maximum is 7.
385
386- `targetLen`=_tlen_, `tlen`=_tlen_:
387    The impact of this field vary depending on selected strategy.
388
389    For ZSTD\_btopt and ZSTD\_btultra, it specifies the minimum match length
390    that causes match finder to stop searching for better matches.
391    A larger `targetLen` usually improves compression ratio
392    but decreases compression speed.
393
394    For ZSTD\_fast, it triggers ultra-fast mode when > 0.
395    The value represents the amount of data skipped between match sampling.
396    Impact is reversed : a larger `targetLen` increases compression speed
397    but decreases compression ratio.
398
399    For all other strategies, this field has no impact.
400
401    The minimum _tlen_ is 0 and the maximum is 999.
402
403- `overlapLog`=_ovlog_,  `ovlog`=_ovlog_:
404    Determine `overlapSize`, amount of data reloaded from previous job.
405    This parameter is only available when multithreading is enabled.
406    Reloading more data improves compression ratio, but decreases speed.
407
408    The minimum _ovlog_ is 0, and the maximum is 9.
409    0 means "no overlap", hence completely independent jobs.
410    9 means "full overlap", meaning up to `windowSize` is reloaded from previous job.
411    Reducing _ovlog_ by 1 reduces the amount of reload by a factor 2.
412    Default _ovlog_ is 6, which means "reload `windowSize / 8`".
413    Exception : the maximum compression level (22) has a default _ovlog_ of 9.
414
415- `ldmHashLog`=_ldmhlog_, `ldmhlog`=_ldmhlog_:
416    Specify the maximum size for a hash table used for long distance matching.
417
418    This option is ignored unless long distance matching is enabled.
419
420    Bigger hash tables usually improve compression ratio at the expense of more
421    memory during compression and a decrease in compression speed.
422
423    The minimum _ldmhlog_ is 6 and the maximum is 26 (default: 20).
424
425- `ldmSearchLength`=_ldmslen_, `ldmslen`=_ldmslen_:
426    Specify the minimum searched length of a match for long distance matching.
427
428    This option is ignored unless long distance matching is enabled.
429
430    Larger/very small values usually decrease compression ratio.
431
432    The minimum _ldmslen_ is 4 and the maximum is 4096 (default: 64).
433
434- `ldmBucketSizeLog`=_ldmblog_, `ldmblog`=_ldmblog_:
435    Specify the size of each bucket for the hash table used for long distance
436    matching.
437
438    This option is ignored unless long distance matching is enabled.
439
440    Larger bucket sizes improve collision resolution but decrease compression
441    speed.
442
443    The minimum _ldmblog_ is 0 and the maximum is 8 (default: 3).
444
445- `ldmHashEveryLog`=_ldmhevery_, `ldmhevery`=_ldmhevery_:
446    Specify the frequency of inserting entries into the long distance matching
447    hash table.
448
449    This option is ignored unless long distance matching is enabled.
450
451    Larger values will improve compression speed. Deviating far from the
452    default value will likely result in a decrease in compression ratio.
453
454    The default value is `wlog - ldmhlog`.
455
456### Example
457The following parameters sets advanced compression options to something
458similar to predefined level 19 for files bigger than 256 KB:
459
460`--zstd`=wlog=23,clog=23,hlog=22,slog=6,slen=3,tlen=48,strat=6
461
462### -B#:
463Select the size of each compression job.
464This parameter is available only when multi-threading is enabled.
465Default value is `4 * windowSize`, which means it varies depending on compression level.
466`-B#` makes it possible to select a custom value.
467Note that job size must respect a minimum value which is enforced transparently.
468This minimum is either 1 MB, or `overlapSize`, whichever is largest.
469
470BUGS
471----
472Report bugs at: https://github.com/facebook/zstd/issues
473
474AUTHOR
475------
476Yann Collet
477