Linux "xz" Command Line Options and Examples
Compress or decompress .xz and .lzma files

xz is a general-purpose data compression tool with command line syntax similar to gzip(1) and bzip2(1). The native file format is the .xz format, but the legacy .


Usage:

xz [option...] [file...]






Command Line Options:

-z
Compress. This is the default operation mode when no operation mode option is specified and no otheroperation mode is implied from the command name (for example, unxz implies --decompress).
xz -z ...
-t
Test the integrity of compressed files. This option is equivalent to --decompress --stdout except thatthe decompressed data is discarded instead of being written to standard output. No files are createdor removed.
xz -t ...
-l
Print information about compressed files. No uncompressed output is produced, and no files are createdor removed. In list mode, the program cannot read the compressed data from standard input or fromother unseekable sources.The default listing shows basic information about files, one file per line. To get more detailedinformation, use also the --verbose option. For even more information, use --verbose twice, but notethat this may be slow, because getting all the extra information requires many seeks. The width ofverbose output exceeds 80 characters, so piping the output to e.g. less -S may be convenient if theterminal isn't wide enough.The exact output may vary between xz versions and different locales. For machine-readable output,
xz -l ...
--robot
Operation modifiers
xz --robot ...
-k
Don't delete the input files.
xz -k ...
-f
This option has several effects:· If the target file already exists, delete it before compressing or decompressing.· Compress or decompress even if the input is a symbolic link to a regular file, has more than onehard link, or has the setuid, setgid, or sticky bit set. The setuid, setgid, and sticky bits arenot copied to the target file.· When used with --decompress --stdout and xz cannot recognize the type of the source file, copy thesource file as is to standard output. This allows xzcat --force to be used like cat(1) for filesthat have not been compressed with xz. Note that in future, xz might support new compressed fileformats, which may make xz decompress more types of files instead of copying them as is to standardoutput. --format=format can be used to restrict xz to decompress only a single file format.
xz -f ...
-c
Write the compressed or decompressed data to standard output instead of a file. This implies --keep.
xz -c ...
--single-stream
Decompress only the first .xz stream, and silently ignore possible remaining input data following thestream. Normally such trailing garbage makes xz display an error.xz never decompresses more than one stream from .lzma files or raw streams, but this option still makesxz ignore the possible trailing data after the .lzma file or raw stream.This option has no effect if the operation mode is not --decompress or --test.
xz --single-stream ...
--no-sparse
Disable creation of sparse files. By default, if decompressing into a regular file, xz tries to makethe file sparse if the decompressed data contains long sequences of binary zeros. It also works whenwriting to standard output as long as standard output is connected to a regular file and certain addi‐tional conditions are met to make it safe. Creating sparse files may save disk space and speed up thedecompression by reducing the amount of disk I/O.
xz --no-sparse ...
-S
When compressing, use .suf as the suffix for the target file instead of .xz or .lzma. If not writingto standard output and the source file already has the suffix .suf, a warning is displayed and the fileis skipped.When decompressing, recognize files with the suffix .suf in addition to files with the .xz, .txz,.lzma, or .tlz suffix. If the source file has the suffix .suf, the suffix is removed to get the targetfilename.When compressing or decompressing raw streams (--format=raw), the suffix must always be specifiedunless writing to standard output, because there is no default suffix for raw streams.
xz -S ...
--files[
Read the filenames to process from file; if file is omitted, filenames are read from standard input.Filenames must be terminated with the newline character. A dash (-) is taken as a regular filename; itdoesn't mean standard input. If filenames are given also as command line arguments, they are processedbefore the filenames read from file.
xz --files[ ...
--files0[
This is identical to --files[=file] except that each filename must be terminated with the null charac‐ter.Basic file format and compression options
xz --files0[ ...
-F
Specify the file format to compress or decompress:auto This is the default. When compressing, auto is equivalent to xz. When decompressing, the for‐mat of the input file is automatically detected. Note that raw streams (created with --for‐mat=raw) cannot be auto-detected.xz Compress to the .xz file format, or accept only .xz files when decompressing.lzma, aloneCompress to the legacy .lzma file format, or accept only .lzma files when decompressing. Thealternative name alone is provided for backwards compatibility with LZMA Utils.raw Compress or uncompress a raw stream (no headers). This is meant for advanced users only. Todecode raw streams, you need use --format=raw and explicitly specify the filter chain, whichnormally would have been stored in the container headers.
xz -F ...
-C
Specify the type of the integrity check. The check is calculated from the uncompressed data and storedin the .xz file. This option has an effect only when compressing into the .xz format; the .lzma formatdoesn't support integrity checks. The integrity check (if any) is verified when the .xz file is decom‐pressed.Supported check types:none Don't calculate an integrity check at all. This is usually a bad idea. This can be useful whenintegrity of the data is verified by other means anyway.crc32 Calculate CRC32 using the polynomial from IEEE-802.3 (Ethernet).crc64 Calculate CRC64 using the polynomial from ECMA-182. This is the default, since it is slightlybetter than CRC32 at detecting damaged files and the speed difference is negligible.sha256 Calculate SHA-256. This is somewhat slower than CRC32 and CRC64.Integrity of the .xz headers is always verified with CRC32. It is not possible to change or disableit.
xz -C ...
--ignore-check
Don't verify the integrity check of the compressed data when decompressing. The CRC32 values in the.xz headers will still be verified normally.Do not use this option unless you know what you are doing. Possible reasons to use this option:· Trying to recover data from a corrupt .xz file.· Speeding up decompression. This matters mostly with SHA-256 or with files that have compressedextremely well. It's recommended to not use this option for this purpose unless the file integrityis verified externally in some other way.
xz --ignore-check ...
-0
Select a compression preset level. The default is -6. If multiple preset levels are specified, thelast one takes effect. If a custom filter chain was already specified, setting a compression presetlevel clears the custom filter chain.The differences between the presets are more significant than with gzip(1) and bzip2(1). The selectedcompression settings determine the memory requirements of the decompressor, thus using a too high pre‐set level might make it painful to decompress the file on an old system with little RAM. Specifically,it's not a good idea to blindly use -9 for everything like it often is with gzip(1) and bzip2(1).
xz -0 ...
-4
Good to very good compression while keeping decompressor memory usage reasonable even for oldsystems. -6 is the default, which is usually a good choice e.g. for distributing files thatneed to be decompressible even on systems with only 16 MiB RAM. (-5e or -6e may be worth con‐sidering too. See --extreme.)
xz -4 ...
-7
These are like -6 but with higher compressor and decompressor memory requirements. These areuseful only when compressing files bigger than 8 MiB, 16 MiB, and 32 MiB, respectively.On the same hardware, the decompression speed is approximately a constant number of bytes of compresseddata per second. In other words, the better the compression, the faster the decompression will usuallybe. This also means that the amount of uncompressed output produced per second can vary a lot.The following table summarises the features of the presets:Preset DictSize CompCPU CompMem DecMem
xz -7 ...
-1
1 MiB 1 9 MiB 2 MiB
xz -1 ...
-2
2 MiB 2 17 MiB 3 MiB
xz -2 ...
-3
4 MiB 3 32 MiB 5 MiB
xz -3 ...
-5
8 MiB 5 94 MiB 9 MiB
xz -5 ...
-6
8 MiB 6 94 MiB 9 MiB
xz -6 ...
-8
32 MiB 6 370 MiB 33 MiB
xz -8 ...
-9
Column descriptions:· DictSize is the LZMA2 dictionary size. It is waste of memory to use a dictionary bigger than thesize of the uncompressed file. This is why it is good to avoid using the presets -7 ... -9 whenthere's no real need for them. At -6 and lower, the amount of memory wasted is usually low enoughto not matter.· CompCPU is a simplified representation of the LZMA2 settings that affect compression speed. Thedictionary size affects speed too, so while CompCPU is the same for levels -6 ... -9, higher levelsstill tend to be a little slower. To get even slower and thus possibly better compression, see
xz -9 ...
--extreme.
· CompMem contains the compressor memory requirements in the single-threaded mode. It may varyslightly between xz versions. Memory requirements of some of the future multithreaded modes may bedramatically higher than that of the single-threaded mode.· DecMem contains the decompressor memory requirements. That is, the compression settings determinethe memory requirements of the decompressor. The exact decompressor memory usage is slightly morethan the LZMA2 dictionary size, but the values in the table have been rounded up to the next fullMiB.
xz --extreme. ...
-e
Use a slower variant of the selected compression preset level (-0 ... -9) to hopefully get a little bitbetter compression ratio, but with bad luck this can also make it worse. Decompressor memory usage isnot affected, but compressor memory usage increases a little at preset levels -0 ... -3.Since there are two presets with dictionary sizes 4 MiB and 8 MiB, the presets -3e and -5e use slightlyfaster settings (lower CompCPU) than -4e and -6e, respectively. That way no two presets are identical.Preset DictSize CompCPU CompMem DecMem
xz -e ...
-0e
256 KiB 8 4 MiB 1 MiB
xz -0e ...
-1e
1 MiB 8 13 MiB 2 MiB
xz -1e ...
-2e
2 MiB 8 25 MiB 3 MiB
xz -2e ...
-3e
4 MiB 7 48 MiB 5 MiB
xz -3e ...
-4e
4 MiB 8 48 MiB 5 MiB
xz -4e ...
-5e
8 MiB 7 94 MiB 9 MiB
xz -5e ...
-6e
8 MiB 8 94 MiB 9 MiB
xz -6e ...
-7e
16 MiB 8 186 MiB 17 MiB
xz -7e ...
-8e
32 MiB 8 370 MiB 33 MiB
xz -8e ...
-9e
For example, there are a total of four presets that use 8 MiB dictionary, whose order from the fastestto the slowest is -5, -6, -5e, and -6e.
xz -9e ...
--block-size
When compressing to the .xz format, split the input data into blocks of size bytes. The blocks arecompressed independently from each other, which helps with multi-threading and makes limited random-access decompression possible. This option is typically used to override the default block size inmulti-threaded mode, but this option can be used in single-threaded mode too.In multi-threaded mode about three times size bytes will be allocated in each thread for bufferinginput and output. The default size is three times the LZMA2 dictionary size or 1 MiB, whichever ismore. Typically a good value is 2-4 times the size of the LZMA2 dictionary or at least 1 MiB. Usingsize less than the LZMA2 dictionary size is waste of RAM because then the LZMA2 dictionary buffer willnever get fully used. The sizes of the blocks are stored in the block headers, which a future versionof xz will use for multi-threaded decompression.In single-threaded mode no block splitting is done by default. Setting this option doesn't affect mem‐ory usage. No size information is stored in block headers, thus files created in single-threaded modewon't be identical to files created in multi-threaded mode. The lack of size information also meansthat a future version of xz won't be able decompress the files in multi-threaded mode.
xz --block-size ...
--block-list
When compressing to the .xz format, start a new block after the given intervals of uncompressed data.The uncompressed sizes of the blocks are specified as a comma-separated list. Omitting a size (two ormore consecutive commas) is a shorthand to use the size of the previous block.If the input file is bigger than the sum of sizes, the last value in sizes is repeated until the end ofthe file. A special value of 0 may be used as the last value to indicate that the rest of the fileshould be encoded as a single block.If one specifies sizes that exceed the encoder's block size (either the default value in threaded modeor the value specified with --block-size=size), the encoder will create additional blocks while keepingthe boundaries specified in sizes. For example, if one specifies --block-size=10MiB
xz --block-list ...
--flush-timeout
When compressing, if more than timeout milliseconds (a positive integer) has passed since the previousflush and reading more input would block, all the pending input data is flushed from the encoder andmade available in the output stream. This can be useful if xz is used to compress data that isstreamed over a network. Small timeout values make the data available at the receiving end with asmall delay, but large timeout values give better compression ratio.This feature is disabled by default. If this option is specified more than once, the last one takeseffect. The special timeout value of 0 can be used to explicitly disable this feature.This feature is not available on non-POSIX systems.This feature is still experimental. Currently xz is unsuitable for decompressing the stream in realtime due to how xz does buffering.
xz --flush-timeout ...
--memlimit-compress
Set a memory usage limit for compression. If this option is specified multiple times, the last onetakes effect.If the compression settings exceed the limit, xz will adjust the settings downwards so that the limitis no longer exceeded and display a notice that automatic adjustment was done. Such adjustments arenot made when compressing with --format=raw or if --no-adjust has been specified. In those cases, anerror is displayed and xz will exit with exit status 1.The limit can be specified in multiple ways:· The limit can be an absolute value in bytes. Using an integer suffix like MiB can be useful. Exam‐ple: --memlimit-compress=80MiB· The limit can be specified as a percentage of total physical memory (RAM). This can be useful espe‐cially when setting the XZ_DEFAULTS environment variable in a shell initialization script that isshared between different computers. That way the limit is automatically bigger on systems with morememory. Example: --memlimit-compress=70%· The limit can be reset back to its default value by setting it to 0. This is currently equivalentto setting the limit to max (no memory usage limit). Once multithreading support has been imple‐mented, there may be a difference between 0 and max for the multithreaded case, so it is recommendedto use 0 instead of max until the details have been decided.See also the section Memory usage.
xz --memlimit-compress ...
--memlimit-decompress
Set a memory usage limit for decompression. This also affects the --list mode. If the operation isnot possible without exceeding the limit, xz will display an error and decompressing the file willfail. See --memlimit-compress=limit for possible ways to specify the limit.
xz --memlimit-decompress ...
-M
This is equivalent to specifying --memlimit-compress=limit --memlimit-decompress=limit.
xz -M ...
--no-adjust
Display an error and exit if the compression settings exceed the memory usage limit. The default is toadjust the settings downwards so that the memory usage limit is not exceeded. Automatic adjusting isalways disabled when creating raw streams (--format=raw).
xz --no-adjust ...
-T
Specify the number of worker threads to use. Setting threads to a special value 0 makes xz use as manythreads as there are CPU cores on the system. The actual number of threads can be less than threads ifthe input file is not big enough for threading with the given settings or if using more threads wouldexceed the memory usage limit.Currently the only threading method is to split the input into blocks and compress them independentlyfrom each other. The default block size depends on the compression level and can be overriden with the
xz -T ...
--block-size=size
Threaded decompression hasn't been implemented yet. It will only work on files that contain multipleblocks with size information in block headers. All files compressed in multi-threaded mode meet thiscondition, but files compressed in single-threaded mode don't even if --block-size=size is used.Custom compressor filter chainsA custom filter chain allows specifying the compression settings in detail instead of relying on the settingsassociated to the presets. When a custom filter chain is specified, preset options (-0 ... -9 and --extreme)earlier on the command line are forgotten. If a preset option is specified after one or more custom filterchain options, the new preset takes effect and the custom filter chain options specified earlier are forgot‐ten.A filter chain is comparable to piping on the command line. When compressing, the uncompressed input goes tothe first filter, whose output goes to the next filter (if any). The output of the last filter gets writtento the compressed file. The maximum number of filters in the chain is four, but typically a filter chain hasonly one or two filters.Many filters have limitations on where they can be in the filter chain: some filters can work only as the lastfilter in the chain, some only as a non-last filter, and some work in any position in the chain. Depending onthe filter, this limitation is either inherent to the filter design or exists to prevent security issues.A custom filter chain is specified by using one or more filter options in the order they are wanted in thefilter chain. That is, the order of filter options is significant! When decoding raw streams (--format=raw),the filter chain is specified in the same order as it was specified when compressing.Filters take filter-specific options as a comma-separated list. Extra commas in options are ignored. Everyoption has a default value, so you need to specify only those you want to change.To see the whole filter chain and options, use xz -vv (that is, use --verbose twice). This works also forviewing the filter chain options used by presets.
xz --block-size=size ...
--lzma2[
Add LZMA1 or LZMA2 filter to the filter chain. These filters can be used only as the last filter inthe chain.LZMA1 is a legacy filter, which is supported almost solely due to the legacy .lzma file format, whichsupports only LZMA1. LZMA2 is an updated version of LZMA1 to fix some practical issues of LZMA1. The.xz format uses LZMA2 and doesn't support LZMA1 at all. Compression speed and ratios of LZMA1 andLZMA2 are practically the same.LZMA1 and LZMA2 share the same set of options:preset=presetReset all LZMA1 or LZMA2 options to preset. Preset consist of an integer, which may be followedby single-letter preset modifiers. The integer can be from 0 to 9, matching the command lineoptions -0 ... -9. The only supported modifier is currently e, which matches --extreme. If nopreset is specified, the default values of LZMA1 or LZMA2 options are taken from the preset 6.dict=sizeDictionary (history buffer) size indicates how many bytes of the recently processed uncompresseddata is kept in memory. The algorithm tries to find repeating byte sequences (matches) in theuncompressed data, and replace them with references to the data currently in the dictionary.The bigger the dictionary, the higher is the chance to find a match. Thus, increasing dictio‐nary size usually improves compression ratio, but a dictionary bigger than the uncompressed fileis waste of memory.Typical dictionary size is from 64 KiB to 64 MiB. The minimum is 4 KiB. The maximum for com‐pression is currently 1.5 GiB (1536 MiB). The decompressor already supports dictionaries up toone byte less than 4 GiB, which is the maximum for the LZMA1 and LZMA2 stream formats.Dictionary size and match finder (mf) together determine the memory usage of the LZMA1 or LZMA2encoder. The same (or bigger) dictionary size is required for decompressing that was used whencompressing, thus the memory usage of the decoder is determined by the dictionary size used whencompressing. The .xz headers store the dictionary size either as 2^n or 2^n + 2^(n-1), so thesesizes are somewhat preferred for compression. Other sizes will get rounded up when stored inthe .xz headers.lc=lc Specify the number of literal context bits. The minimum is 0 and the maximum is 4; the defaultis 3. In addition, the sum of lc and lp must not exceed 4.All bytes that cannot be encoded as matches are encoded as literals. That is, literals are sim‐ply 8-bit bytes that are encoded one at a time.The literal coding makes an assumption that the highest lc bits of the previous uncompressedbyte correlate with the next byte. E.g. in typical English text, an upper-case letter is oftenfollowed by a lower-case letter, and a lower-case letter is usually followed by another lower-case letter. In the US-ASCII character set, the highest three bits are 010 for upper-case let‐ters and 011 for lower-case letters. When lc is at least 3, the literal coding can take advan‐tage of this property in the uncompressed data.The default value (3) is usually good. If you want maximum compression, test lc=4. Sometimesit helps a little, and sometimes it makes compression worse. If it makes it worse, test e.g.lc=2 too.lp=lp Specify the number of literal position bits. The minimum is 0 and the maximum is 4; the defaultis 0.Lp affects what kind of alignment in the uncompressed data is assumed when encoding literals.See pb below for more information about alignment.pb=pb Specify the number of position bits. The minimum is 0 and the maximum is 4; the default is 2.Pb affects what kind of alignment in the uncompressed data is assumed in general. The defaultmeans four-byte alignment (2^pb=2^2=4), which is often a good choice when there's no betterguess.When the aligment is known, setting pb accordingly may reduce the file size a little. E.g. withtext files having one-byte alignment (US-ASCII, ISO-8859-*, UTF-8), setting pb=0 can improvecompression slightly. For UTF-16 text, pb=1 is a good choice. If the alignment is an odd num‐ber like 3 bytes, pb=0 might be the best choice.Even though the assumed alignment can be adjusted with pb and lp, LZMA1 and LZMA2 still slightlyfavor 16-byte alignment. It might be worth taking into account when designing file formats thatare likely to be often compressed with LZMA1 or LZMA2.mf=mf Match finder has a major effect on encoder speed, memory usage, and compression ratio. UsuallyHash Chain match finders are faster than Binary Tree match finders. The default depends on thepreset: 0 uses hc3, 1-3 use hc4, and the rest use bt4.The following match finders are supported. The memory usage formulas below are rough approxima‐tions, which are closest to the reality when dict is a power of two.hc3 Hash Chain with 2- and 3-byte hashingMinimum value for nice: 3Memory usage:dict * 7.5 (if dict <= 16 MiB);dict * 5.5 + 64 MiB (if dict > 16 MiB)hc4 Hash Chain with 2-, 3-, and 4-byte hashingMinimum value for nice: 4Memory usage:dict * 7.5 (if dict <= 32 MiB);dict * 6.5 (if dict > 32 MiB)bt2 Binary Tree with 2-byte hashingMinimum value for nice: 2Memory usage: dict * 9.5bt3 Binary Tree with 2- and 3-byte hashingMinimum value for nice: 3Memory usage:dict * 11.5 (if dict <= 16 MiB);dict * 9.5 + 64 MiB (if dict > 16 MiB)bt4 Binary Tree with 2-, 3-, and 4-byte hashingMinimum value for nice: 4Memory usage:dict * 11.5 (if dict <= 32 MiB);dict * 10.5 (if dict > 32 MiB)mode=modeCompression mode specifies the method to analyze the data produced by the match finder. Sup‐ported modes are fast and normal. The default is fast for presets 0-3 and normal for presets
xz --lzma2[ ...
-9.
Usually fast is used with Hash Chain match finders and normal with Binary Tree match finders.This is also what the presets do.nice=niceSpecify what is considered to be a nice length for a match. Once a match of at least nice bytesis found, the algorithm stops looking for possibly better matches.Nice can be 2-273 bytes. Higher values tend to give better compression ratio at the expense ofspeed. The default depends on the preset.depth=depthSpecify the maximum search depth in the match finder. The default is the special value of 0,which makes the compressor determine a reasonable depth from mf and nice.Reasonable depth for Hash Chains is 4-100 and 16-1000 for Binary Trees. Using very high valuesfor depth can make the encoder extremely slow with some files. Avoid setting the depth over1000 unless you are prepared to interrupt the compression in case it is taking far too long.When decoding raw streams (--format=raw), LZMA2 needs only the dictionary size. LZMA1 needs also lc,lp, and pb.
xz -9. ...
--sparc[
Add a branch/call/jump (BCJ) filter to the filter chain. These filters can be used only as a non-lastfilter in the filter chain.A BCJ filter converts relative addresses in the machine code to their absolute counterparts. Thisdoesn't change the size of the data, but it increases redundancy, which can help LZMA2 to produce
xz --sparc[ ...
--delta[
Add the Delta filter to the filter chain. The Delta filter can be only used as a non-last filter inthe filter chain.Currently only simple byte-wise delta calculation is supported. It can be useful when compressing e.g.uncompressed bitmap images or uncompressed PCM audio. However, special purpose algorithms may givesignificantly better results than Delta + LZMA2. This is true especially with audio, which compressesfaster and better e.g. with flac(1).Supported options:dist=distanceSpecify the distance of the delta calculation in bytes. distance must be 1-256. The default is1.For example, with dist=2 and eight-byte input A1 B1 A2 B3 A3 B5 A4 B7, the output will be A1 B101 02 01 02 01 02.Other options
xz --delta[ ...
-q
Suppress warnings and notices. Specify this twice to suppress errors too. This option has no effecton the exit status. That is, even if a warning was suppressed, the exit status to indicate a warningis still used.
xz -q ...
-v
Be verbose. If standard error is connected to a terminal, xz will display a progress indicator. Spec‐ifying --verbose twice will give even more verbose output.The progress indicator shows the following information:· Completion percentage is shown if the size of the input file is known. That is, the percentage can‐not be shown in pipes.· Amount of compressed data produced (compressing) or consumed (decompressing).· Amount of uncompressed data consumed (compressing) or produced (decompressing).· Compression ratio, which is calculated by dividing the amount of compressed data processed so far bythe amount of uncompressed data processed so far.· Compression or decompression speed. This is measured as the amount of uncompressed data consumed(compression) or produced (decompression) per second. It is shown after a few seconds have passedsince xz started processing the file.· Elapsed time in the format M:SS or H:MM:SS.· Estimated remaining time is shown only when the size of the input file is known and a couple of sec‐onds have already passed since xz started processing the file. The time is shown in a less preciseformat which never has any colons, e.g. 2 min 30 s.When standard error is not a terminal, --verbose will make xz print the filename, compressed size,uncompressed size, compression ratio, and possibly also the speed and elapsed time on a single line tostandard error after compressing or decompressing the file. The speed and elapsed time are includedonly when the operation took at least a few seconds. If the operation didn't finish, e.g. due to userinterruption, also the completion percentage is printed if the size of the input file is known.
xz -v ...
-Q
Don't set the exit status to 2 even if a condition worth a warning was detected. This option doesn'taffect the verbosity level, thus both --quiet and --no-warn have to be used to not display warnings andto not alter the exit status.
xz -Q ...
--info-memory
Display, in human-readable format, how much physical memory (RAM) xz thinks the system has and the mem‐ory usage limits for compression and decompression, and exit successfully.
xz --info-memory ...
-h
Display a help message describing the most commonly used options, and exit successfully.
xz -h ...
-H
Display a help message describing all features of xz, and exit successfully
xz -H ...
-V
Display the version number of xz and liblzma in human readable format. To get machine-parsable output,specify --robot before --version.ROBOT MODEThe robot mode is activated with the --robot option. It makes the output of xz easier to parse by other pro‐grams. Currently --robot is supported only together with --version, --info-memory, and --list. It will besupported for compression and decompression in the future.Versionxz --robot --version will print the version number of xz and liblzma in the following format:XZ_VERSION=XYYYZZZSLIBLZMA_VERSION=XYYYZZZSX Major version.YYY Minor version. Even numbers are stable. Odd numbers are alpha or beta versions.ZZZ Patch level for stable releases or just a counter for development releases.S Stability. 0 is alpha, 1 is beta, and 2 is stable. S should be always 2 when YYY is even.XYYYZZZS are the same on both lines if xz and liblzma are from the same XZ Utils release.Examples: 4.999.9beta is 49990091 and 5.0.0 is 50000002.Memory limit informationxz --robot --info-memory prints a single line with three tab-separated columns:1. Total amount of physical memory (RAM) in bytes2. Memory usage limit for compression in bytes. A special value of zero indicates the default setting, whichfor single-threaded mode is the same as no limit.3. Memory usage limit for decompression in bytes. A special value of zero indicates the default setting,which for single-threaded mode is the same as no limit.In the future, the output of xz --robot --info-memory may have more columns, but never more than a singleline.List modexz --robot --list uses tab-separated output. The first column of every line has a string that indicates thetype of the information found on that line:name This is always the first line when starting to list a file. The second column on the line is the file‐name.file This line contains overall information about the .xz file. This line is always printed after the nameline.stream This line type is used only when --verbose was specified. There are as many stream lines as there arestreams in the .xz file.block This line type is used only when --verbose was specified. There are as many block lines as there areblocks in the .xz file. The block lines are shown after all the stream lines; different line types arenot interleaved.summaryThis line type is used only when --verbose was specified twice. This line is printed after all blocklines. Like the file line, the summary line contains overall information about the .xz file.totals This line is always the very last line of the list output. It shows the total counts and sizes.The columns of the file lines:2. Number of streams in the file3. Total number of blocks in the stream(s)4. Compressed size of the file5. Uncompressed size of the file6. Compression ratio, for example 0.123. If ratio is over 9.999, three dashes (---) are displayedinstead of the ratio.7. Comma-separated list of integrity check names. The following strings are used for the known checktypes: None, CRC32, CRC64, and SHA-256. For unknown check types, Unknown-N is used, where N is theCheck ID as a decimal number (one or two digits).8. Total size of stream padding in the fileThe columns of the stream lines:2. Stream number (the first stream is 1)3. Number of blocks in the stream4. Compressed start offset5. Uncompressed start offset6. Compressed size (does not include stream padding)7. Uncompressed size8. Compression ratio9. Name of the integrity check10. Size of stream paddingThe columns of the block lines:2. Number of the stream containing this block3. Block number relative to the beginning of the stream (the first block is 1)4. Block number relative to the beginning of the file5. Compressed start offset relative to the beginning of the file6. Uncompressed start offset relative to the beginning of the file7. Total compressed size of the block (includes headers)8. Uncompressed size9. Compression ratio10. Name of the integrity checkIf --verbose was specified twice, additional columns are included on the block lines. These are not displayedwith a single --verbose, because getting this information requires many seeks and can thus be slow:11. Value of the integrity check in hexadecimal12. Block header size13. Block flags: c indicates that compressed size is present, and u indicates that uncompressed size ispresent. If the flag is not set, a dash (-) is shown instead to keep the string length fixed. Newflags may be added to the end of the string in the future.14. Size of the actual compressed data in the block (this excludes the block header, block padding, andcheck fields)15. Amount of memory (in bytes) required to decompress this block with this xz version16. Filter chain. Note that most of the options used at compression time cannot be known, because onlythe options that are needed for decompression are stored in the .xz headers.The columns of the summary lines:2. Amount of memory (in bytes) required to decompress this file with this xz version3. yes or no indicating if all block headers have both compressed size and uncompressed size stored inthemSince xz 5.1.2alpha:4. Minimum xz version required to decompress the fileThe columns of the totals line:2. Number of streams3. Number of blocks4. Compressed size5. Uncompressed size6. Average compression ratio7. Comma-separated list of integrity check names that were present in the files8. Stream padding size9. Number of files. This is here to keep the order of the earlier columns the same as on file lines.If --verbose was specified twice, additional columns are included on the totals line:10. Maximum amount of memory (in bytes) required to decompress the files with this xz version11. yes or no indicating if all block headers have both compressed size and uncompressed size stored inthemSince xz 5.1.2alpha:12. Minimum xz version required to decompress the fileFuture versions may add new line types and new columns can be added to the existing line types, but the exist‐ing columns won't be changed.EXIT STATUS0 All is good.1 An error occurred.2 Something worth a warning occurred, but no actual errors occurred.Notices (not warnings or errors) printed on standard error don't affect the exit status.ENVIRONMENTxz parses space-separated lists of options from the environment variables XZ_DEFAULTS and XZ_OPT, in thisorder, before parsing the options from the command line. Note that only options are parsed from the environ‐ment variables; all non-options are silently ignored. Parsing is done with getopt_long(3) which is used alsofor the command line arguments.XZ_DEFAULTSUser-specific or system-wide default options. Typically this is set in a shell initialization scriptto enable xz's memory usage limiter by default. Excluding shell initialization scripts and similarspecial cases, scripts must never set or unset XZ_DEFAULTS.XZ_OPT This is for passing options to xz when it is not possible to set the options directly on the xz commandline. This is the case e.g. when xz is run by a script or tool, e.g. GNU tar(1):XZ_OPT=-2v tar caf foo.tar.xz fooScripts may use XZ_OPT e.g. to set script-specific default compression options. It is still recom‐mended to allow users to override XZ_OPT if that is reasonable, e.g. in sh(1) scripts one may use some‐thing like this:XZ_OPT=${XZ_OPT-"-7e"}export XZ_OPTLZMA UTILS COMPATIBILITYThe command line syntax of xz is practically a superset of lzma, unlzma, and lzcat as found from LZMA Utils4.32.x. In most cases, it is possible to replace LZMA Utils with XZ Utils without breaking existing scripts.There are some incompatibilities though, which may sometimes cause problems.Compression preset levelsThe numbering of the compression level presets is not identical in xz and LZMA Utils. The most important dif‐ference is how dictionary sizes are mapped to different presets. Dictionary size is roughly equal to thedecompressor memory usage.Level xz LZMA Utils
xz -V ...
--check=none
Outside embedded systems, all .xz format decompressors support all the check types, or at least are able todecompress the file without verifying the integrity check if the particular check is not supported.XZ Embedded supports BCJ filters, but only with the default start offset.EXAMPLESBasicsCompress the file foo into foo.xz using the default compression level (-6), and remove foo if compression issuccessful:xz fooDecompress bar.xz into bar and don't remove bar.xz even if decompression is successful:xz -dk bar.xzCreate baz.tar.xz with the preset -4e (-4 --extreme), which is slower than e.g. the default -6, but needs lessmemory for compression and decompression (48 MiB and 5 MiB, respectively):tar cf - baz | xz -4e > baz.tar.xzA mix of compressed and uncompressed files can be decompressed to standard output with a single command:xz -dcf a.txt b.txt.xz c.txt d.txt.lzma > abcd.txtParallel compression of many filesOn GNU and *BSD, find(1) and xargs(1) can be used to parallelize compression of many files:find . -type f \! -name '*.xz' -print0 \| xargs -0r -P4 -n16 xz -T1The -P option to xargs(1) sets the number of parallel xz processes. The best value for the -n option dependson how many files there are to be compressed. If there are only a couple of files, the value should probablybe 1; with tens of thousands of files, 100 or even more may be appropriate to reduce the number of xz pro‐cesses that xargs(1) will eventually create.The option -T1 for xz is there to force it to single-threaded mode, because xargs(1) is used to control theamount of parallelization.Robot modeCalculate how many bytes have been saved in total after compressing multiple files:xz --robot --list *.xz | awk '/^totals/{print $5-$4}'A script may want to know that it is using new enough xz. The following sh(1) script checks that the versionnumber of the xz tool is at least 5.0.0. This method is compatible with old beta versions, which didn't sup‐port the --robot option:if ! eval "$(xz --robot --version 2> /dev/null)" ||[ "$XZ_VERSION" -lt 50000002 ]; thenecho "Your xz is too old."fiunset XZ_VERSION LIBLZMA_VERSIONSet a memory usage limit for decompression using XZ_OPT, but if a limit has already been set, don't increaseit:NEWLIM=$((123 << 20)) # 123 MiBOLDLIM=$(xz --robot --info-memory | cut -f3)if [ $OLDLIM -eq 0 -o $OLDLIM -gt $NEWLIM ]; thenXZ_OPT="$XZ_OPT --memlimit-decompress=$NEWLIM"export XZ_OPTfiCustom compressor filter chainsThe simplest use for custom filter chains is customizing a LZMA2 preset. This can be useful, because the pre‐sets cover only a subset of the potentially useful combinations of compression settings.The CompCPU columns of the tables from the descriptions of the options -0 ... -9 and --extreme are useful whencustomizing LZMA2 presets. Here are the relevant parts collected from those two tables:Preset CompCPU
xz --check=none ...