Section: XZ Utils (1)
Updated: 2009-08-27
Index Return to Main Contents





unxz is equivalent to xz --decompress.
xzcat is equivalent to xz --decompress --stdout.
lzma is equivalent to xz --format=lzma.



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 also the legacy .lzma format and raw compressed streams with no container format headers are supported.






File is not a regular file. Symbolic links are not followed, thus they are never considered to be regular files.
File has more than one hardlink.
File has setuid, setgid, or sticky bit set.
The operation mode is set to decompress, and the file doesn't have a suffix of any of the supported file formats (.xz, .txz, .lzma, or .tlz).




Memory usage

The memory usage of xz varies from a few hundred kilobytes to several gigabytes depending on the compression settings. The settings used when compressing a file affect also the memory usage of the decompressor. Typically the decompressor needs only 5 % to 20 % of the amount of RAM that the compressor needed when creating the file. Still, the worst-case memory usage of the decompressor is several gigabytes.

To prevent uncomfortable surprises caused by huge memory usage, xz has a built-in memory usage limiter. The default limit is 40 % of total physical RAM. While operating systems provide ways to limit the memory usage of processes, relying on it wasn't deemed to be flexible enough.

When compressing, if the selected compression settings exceed the memory usage limit, the settings are automatically adjusted downwards and a notice about this is displayed. As an exception, if the memory usage limit is exceeded when compressing with --format=raw, an error is displayed and xz will exit with exit status 1.

If source file cannot be decompressed without exceeding the memory usage limit, an error message is displayed and the file is skipped. Note that compressed files may contain many blocks, which may have been compressed with different settings. Typically all blocks will have roughly the same memory requirements, but it is possible that a block later in the file will exceed the memory usage limit, and an error about too low memory usage limit gets displayed after some data has already been decompressed.

The absolute value of the active memory usage limit can be seen near the bottom of the output of --long-help. The default limit can be overriden with --memory=limit.  



Integer suffixes and special values

k or kB
The integer is multiplied by 1,000 (10^3). For example, 5k or 5kB equals 5000.
Ki or KiB
The integer is multiplied by 1,024 (2^10).
M or MB
The integer is multiplied by 1,000,000 (10^6).
Mi or MiB
The integer is multiplied by 1,048,576 (2^20).
G or GB
The integer is multiplied by 1,000,000,000 (10^9).
Gi or GiB
The integer is multiplied by 1,073,741,824 (2^30).


Operation mode

-z, --compress
Compress. This is the default operation mode when no operation mode option is specified, and no other operation mode is implied from the command name (for example, unxz implies --decompress).
-d, --decompress, --uncompress
-t, --test
Test the integrity of compressed files. No files are created or removed. This option is equivalent to --decompress --stdout except that the decompressed data is discarded instead of being written to standard output.
-l, --list
This feature has not been implemented yet.

Operation modifiers

-k, --keep
Keep (don't delete) the input files.
-f, --force
This option has several effects:
Compress or decompress even if the input is not a regular file, has more than one hardlink, or has setuid, setgid, or sticky bit set. The setuid, setgid, and sticky bits are not copied to the target file.
If combined with --decompress --stdout and xz doesn't recognize the type of the source file, xz will copy the source file as is to standard output. This allows using xzcat --force like cat(1) for files that have not been compressed with xz. Note that in future, xz might support new compressed file formats, which may make xz decompress more types of files instead of copying them as is to standard output. --format=format can be used to restrict xz to decompress only a single file format.
Allow writing compressed data to a terminal, and reading compressed data from a terminal.
-c, --stdout, --to-stdout
-S .suf, --suffix=.suf
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. If filenames are given also as command line arguments, they are processed before the filenames read from file.
This is identical to --files[=file] except that the filenames must be terminated with the null character.

Basic file format and compression options

-F format, --format=format
Specify the file format to compress or decompress:
auto: This is the default. When compressing, auto is equivalent to xz. When decompressing, the format of the input file is autodetected. Note that raw streams (created with --format=raw) cannot be autodetected.
raw: Compress or uncompress a raw stream (no headers). This is meant for advanced users only. To decode raw streams, you need to set not only --format=raw but also specify the filter chain, which would normally be stored in the container format headers.
-C check, --check=check
Specify the type of the integrity check, which is calculated from the uncompressed data. This option has an effect only when compressing into the .xz format; the .lzma format doesn't support integrity checks. The integrity check (if any) is verified when the .xz file is decompressed.
Supported check types:
crc32: Calculate CRC32 using the polynomial from IEEE-802.3 (Ethernet).
sha256: Calculate SHA-256. This is somewhat slower than CRC32 and CRC64.
-0 ... -9
Select compression preset. If a preset level is specified multiple times, the last one takes effect.
The compression preset levels can be categorised roughly into three categories:
-0 ... -2
Fast presets with relatively low memory usage. -1 and -2 should give compression speed and ratios comparable to bzip2 -1 and bzip2 -9, respectively. Currently -0 is not very good (not much faster than -1 but much worse compression). In future, -0 may be indicate some fast algorithm instead of LZMA2.
-3 ... -5
Good compression ratio with low to medium memory usage. These are significantly slower than levels 0-2.
-6 ... -9
Excellent compression with medium to high memory usage. These are also slower than the lower preset levels. The default is -6. Unless you want to maximize the compression ratio, you probably don't want a higher preset level than -7 due to speed and memory usage.
The exact compression settings (filter chain) used by each preset may vary between xz versions. The settings may also vary between files being compressed, if xz determines that modified settings will probably give better compression ratio without significantly affecting compression time or memory usage.
Because the settings may vary, the memory usage may vary too. The following table lists the maximum memory usage of each preset level, which won't be exceeded even in future versions of xz.
FIXME: The table below is just a rough idea.
-0    6 MiB    1 MiB    
-1    6 MiB    1 MiB    
-2    10 MiB    1 MiB    
-3    20 MiB    2 MiB    
-4    30 MiB    3 MiB    
-5    60 MiB    6 MiB    
-6    100 MiB    10 MiB    
-7    200 MiB    20 MiB    
-8    400 MiB    40 MiB    
-9    800 MiB    80 MiB    
When compressing, xz automatically adjusts the compression settings downwards if the memory usage limit would be exceeded, so it is safe to specify a high preset level even on systems that don't have lots of RAM.
--fast and --best
Especially the name of --best is misleading, because the definition of best depends on the input data, and that usually people don't want the very best compression ratio anyway, because it would be very slow.
-e, --extreme
Modify the compression preset (-0 ... -9) so that a little bit better compression ratio can be achieved without increasing memory usage of the compressor or decompressor (exception: compressor memory usage may increase a little with presets -0 ... -2). The downside is that the compression time will increase dramatically (it can easily double).
-M limit, --memory=limit
Set the memory usage limit. If this option is specied multiple times, the last one takes effect. The limit can be specified in multiple ways:
The limit can be specified as a percentage of physical RAM. Example: --memory=70%
The limit can be reset back to its default value (currently 40 % of physical RAM) by setting it to 0.
The memory usage limiting can be effectively disabled by setting limit to max. This isn't recommended. It's usually better to use, for example, --memory=90%.
The current limit can be seen near the bottom of the output of the --long-help option.
-T threads, --threads=threads
Specify the maximum number of worker threads to use. The default is the number of available CPU cores. You can see the current value of threads near the end of the output of the --long-help option.
The actual number of worker threads can be less than threads if using more threads would exceed the memory usage limit. In addition to CPU-intensive worker threads, xz may use a few auxiliary threads, which don't use a lot of CPU time.

Custom compressor filter chains






Add LZMA1 or LZMA2 filter to the filter chain. These filter can be used only as the last filter in the chain.
LZMA1 is a legacy filter, which is supported almost solely due to the legacy .lzma file format, which supports 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 and LZMA2 are practically the same.
LZMA1 and LZMA2 share the same set of options:
Dictionary (history buffer) size indicates how many bytes of the recently processed uncompressed data is kept in memory. One method to reduce size of the uncompressed data is to store distance-length pairs, which indicate what data to repeat from the dictionary buffer. The bigger the dictionary, the better the compression ratio usually is, but dictionaries bigger than the uncompressed data are waste of RAM.
Typical dictionary size is from 64 KiB to 64 MiB. The minimum is 4 KiB. The maximum for compression is currently 1.5 GiB. The decompressor already supports dictionaries up to one byte less than 4 GiB, which is the maximum for LZMA1 and LZMA2 stream formats.
Dictionary size has the biggest effect on compression ratio. Dictionary size and match finder together determine the memory usage of the LZMA1 or LZMA2 encoder. The same dictionary size is required for decompressing that was used when compressing, thus the memory usage of the decoder is determined by the dictionary size used when compressing.
Compression mode specifies the function used to analyze the data produced by the match finder. Supported modes are fast and normal. The default is fast for presets 0-2 and normal for presets 3-9.
Match finder has a major effect on encoder speed, memory usage, and compression ratio. Usually Hash Chain match finders are faster than Binary Tree match finders. Hash Chains are usually used together with mode=fast and Binary Trees with mode=normal. The memory usage formulas are only rough estimates, which are closest to reality when dict is a power of two.
Hash Chain with 2- and 3-byte hashing
Minimum value for nice: 3
Minimum value for nice: 4
Memory usage: dict * 7.5
Binary Tree with 2-byte hashing
Minimum value for nice: 2
Memory usage: dict * 9.5
Binary Tree with 2- and 3-byte hashing
Minimum value for nice: 3
Minimum value for nice: 4
Memory usage: dict * 11.5
nice can be 2-273 bytes. Higher values tend to give better compression ratio at expense of speed. The default depends on the preset level.
Specify the maximum search depth in the match finder. The default is the special value 0, which makes the compressor determine a reasonable depth from mf and nice.
Using very high values for depth can make the encoder extremely slow with carefully crafted files. Avoid setting the depth over 1000 unless you are prepared to interrupt the compression in case it is taking too long.
When decoding raw streams (--format=raw), LZMA2 needs only the value of dict. LZMA1 needs also lc, lp, and pb.
Add a branch/call/jump (BCJ) filter to the filter chain. These filters can be used only as non-last filter in the filter chain.
A BCJ filter converts relative addresses in the machine code to their absolute counterparts. This doesn't change the size of the data, but it increases redundancy, which allows e.g. LZMA2 to get better compression ratio.
The BCJ filters are always reversible, so using a BCJ filter for wrong type of data doesn't cause any data loss. However, applying a BCJ filter for wrong type of data is a bad idea, because it tends to make the compression ratio worse.
Different instruction sets have have different alignment:
FilterAlignment    Notes
x861    32-bit and 64-bit x86
PowerPC4    Big endian only
ARM4    Little endian only
ARM-Thumb2    Little endian only
IA-6416    Big or little endian
SPARC4    Big or little endian
All BCJ filters support the same options:
Specifying a non-zero start offset is probably useful only if the executable has multiple sections, and there are many cross-section jumps or calls. Applying a BCJ filter separately for each section with proper start offset and then compressing the result as a single chunk may give some improvement in compression ratio compared to applying the BCJ filter with the default offset for the whole executable.
Add Delta filter to the filter chain. The Delta filter can be used only as non-last filter in the filter chain.
Supported options:
Specify the distance of the delta calculation as bytes. distance must be 1-256. The default is 1.

Other options

-q, --quiet
-v, --verbose
Be verbose. If standard error is connected to a terminal, xz will display a progress indicator. Specifying --verbose twice will give even more verbose output (useful mostly for debugging).
-Q, --no-warn
-h, --help
-H, --long-help
-V, --version
Display the version number of xz and liblzma.


All is good.
An error occurred.
Something worth a warning occurred, but no actual errors occurred.



A space-separated list of options is parsed from XZ_OPT before parsing the options given on the command line. Note that only options are parsed from XZ_OPT; all non-options are silently ignored. Parsing is done with getopt_long(3) which is used also for the command line arguments.



Compression preset levels

LevelxzLZMA Utils
-164 KiB    64 KiB    
-2512 KiB    1 MiB    
-31 MiB    512 KiB    
-42 MiB    1 MiB    
-54 MiB    2 MiB    
-68 MiB    4 MiB    
-716 MiB    8 MiB    
-832 MiB    16 MiB    
-964 MiB    32 MiB    


LevelxzLZMA Utils 4.32.x
-12 MiB    2 MiB    
-25 MiB    12 MiB    
-313 MiB    12 MiB    
-425 MiB    16 MiB    
-548 MiB    26 MiB    
-694 MiB    45 MiB    
-7186 MiB    83 MiB    
-8370 MiB    159 MiB    
-9674 MiB    311 MiB    

The default preset level in LZMA Utils is -7 while in XZ Utils it is -6, so both use 8 MiB dictionary by default.  

Streamed vs. non-streamed .lzma files

Uncompressed size of the file can be stored in the .lzma header. LZMA Utils does that when compressing regular files. The alternative is to mark that uncompressed size is unknown and use end of payload marker to indicate where the decompressor should stop. LZMA Utils uses this method when uncompressed size isn't known, which is the case for example in pipes.

xz supports decompressing .lzma files with or without end of payload marker, but all .lzma files created by xz will use end of payload marker and have uncompressed size marked as unknown in the .lzma header. This may be a problem in some (uncommon) situations. For example, a .lzma decompressor in an embedded device might work only with files that have known uncompressed size. If you hit this problem, you need to use LZMA Utils or LZMA SDK to create .lzma files with known uncompressed size.  

Unsupported .lzma files


The implementation of the LZMA1 filter in liblzma requires that the sum of lc and lp must not exceed 4. Thus, .lzma files which exceed this limitation, cannot be decompressed with xz.

LZMA Utils creates only .lzma files which have dictionary size of 2^n (a power of 2), but accepts files with any dictionary size. liblzma accepts only .lzma files which have dictionary size of 2^n or 2^n + 2^(n-1). This is to decrease false positives when autodetecting .lzma files.


Trailing garbage


If there is data left after the first .lzma stream, xz considers the file to be corrupt. This may break obscure scripts which have assumed that trailing garbage is ignored.  



Compressed output may vary



Embedded .xz decompressors

Embedded .xz decompressor implementations like XZ Embedded don't necessarily support files created with check types other than none and crc32. Since the default is --check=crc64, you must use --check=none or --check=crc32 when creating files for embedded systems.








Memory usage
Integer suffixes and special values
Operation mode
Operation modifiers
Basic file format and compression options
Custom compressor filter chains
Other options
Compression preset levels
Streamed vs. non-streamed .lzma files
Unsupported .lzma files
Trailing garbage
Compressed output may vary
Embedded .xz decompressors

This document was created by man2html, using the manual pages.