NAME
xz, unxz, xzcat, lzma, unlzma, lzcat - Compress or decompress .xz and .lzma files
SYNOPSIS
xz [option]... [file]...
unxz is equivalent to xz --decompress. xzcat is equivalent to xz --decompress --stdout. lzma is equivalent to xz --format=lzma. unlzma is equivalent to xz --format=lzma --decompress. lzcat is equivalent to xz --format=lzma --decompress --stdout.
When writing scripts that need to decompress files, it is recommended to always use the name xz with appropriate arguments (xz -d or xz -dc) instead of the names unxz and xzcat.
DESCRIPTION
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.
xz compresses or decompresses each file according to the selected operation mode. If no files are given or file is -, xz reads from standard input and writes the processed data to standard output. xz will refuse (display an error and skip the file) to write compressed data to standard output if it is a terminal. Similarly, xz will refuse to read compressed data from standard input if it is a terminal.
Unless --stdout is specified, files other than - are written to a new file whose name is derived from the source file name:
o | When compressing, the suffix of the target file format (.xz or .lzma) is appended to the source filename to get the target filename. |
o | When decompressing, the .xz or .lzma suffix is removed from the filename to get the target filename. xz also recognizes the suffixes .txz and .tlz, and replaces them with the .tar suffix. |
Unless writing to standard output, xz will display a warning and skip the file if any of the following applies:
o | File is not a regular file. Symbolic links are not followed, thus they are never considered to be regular files. |
o | File has more than one hardlink. |
o | File has setuid, setgid, or sticky bit set. |
o | The operation mode is set to compress, and the file already has a suffix of the target file format (.xz or .txz when compressing to the .xz format, and .lzma or .tlz when compressing to the .lzma format). |
o | The operation mode is set to decompress, and the file doesnt have a suffix of any of the supported file formats (.xz, .txz, .lzma, or .tlz). |
Once the target file has been successfully closed, the source file is removed unless --keep was specified. The source file is never removed if the output is written to standard output.
Sending SIGINFO or SIGUSR1 to the xz process makes it print progress information to standard error. This has only limited use since when standard error is a terminal, using --verbose will display an automatically updating progress indicator.
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 wasnt 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.
OPTIONS
Integer suffixes and special values
In most places where an integer argument is expected, an optional suffix is supported to easily indicate large integers. There must be no space between the integer and the suffix.
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
If multiple operation mode options are given, the last one takes effect.
-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 | |
Decompress. | |
-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 | |
View information about the compressed files. No uncompressed output is produced, and no files are created or removed. In list mode, the program cannot read the compressed data from standard input or from other unseekable sources. | |
This feature has not been implemented yet. | |
Operation modifiers
-k, --keep | |||||||||
Keep (dont delete) the input files. | |||||||||
-f, --force | |||||||||
This option has several effects:
| |||||||||
-c, --stdout, --to-stdout | |||||||||
Write the compressed or decompressed data to standard output instead of a file. This implies --keep. | |||||||||
-S .suf, --suffix=.suf | |||||||||
When compressing, use .suf as the suffix for the target file instead of .xz or .lzma. If not writing to standard output and the source file already has the suffix .suf, a warning is displayed and the file is skipped. | |||||||||
When decompressing, recognize also 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 target filename. | |||||||||
When compressing or decompressing raw streams (--format=raw), the suffix must always be specified unless writing to standard output, because there is no default suffix for raw streams. | |||||||||
--files[=file] | |||||||||
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. | |||||||||
--files0[=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:
| ||||||||||||||||||||||||||||||||||||
-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 doesnt support integrity checks. The integrity check (if any) is verified when the .xz file is decompressed. | ||||||||||||||||||||||||||||||||||||
Supported
check types:
| ||||||||||||||||||||||||||||||||||||
Integrity of the .xz headers is always verified with CRC32. It is not possible to change or disable it. | ||||||||||||||||||||||||||||||||||||
-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:
| ||||||||||||||||||||||||||||||||||||
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 wont be exceeded even in future versions of xz. | ||||||||||||||||||||||||||||||||||||
FIXME: The table below is just a rough idea.
| ||||||||||||||||||||||||||||||||||||
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 dont have lots of RAM. | ||||||||||||||||||||||||||||||||||||
--fast and --best | ||||||||||||||||||||||||||||||||||||
These are somewhat misleading aliases for -0 and -9, respectively. These are provided only for backwards compatibility with LZMA Utils. Avoid using these options. | ||||||||||||||||||||||||||||||||||||
Especially the name of --best is misleading, because the definition of best depends on the input data, and that usually people dont 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 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 dont use a lot of CPU time. | ||||||||||||||||||||||||||||||||||||
Multithreaded compression and decompression are not implemented yet, so this option has no effect for now. | ||||||||||||||||||||||||||||||||||||
Custom compressor filter chains
A custom filter chain allows specifying the compression settings in detail instead of relying on the settings associated to the preset levels. When a custom filter chain is specified, the compression preset level options (-0 ... -9 and --extreme) are silently ignored.
A filter chain is comparable to piping on the UN*X command line. When compressing, the uncompressed input goes to the first filter, whose output goes to the next filter (if any). The output of the last filter gets written to the compressed file. The maximum number of filters in the chain is four, but typically a filter chain has only one or two filters.
Many filters have limitations where they can be in the filter chain: some filters can work only as the last filter in the chain, some only as a non-last filter, and some work in any position in the chain. Depending on the 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 the filter 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. Every option has a default value, so you need to specify only those you want to change.
--lzma1[=options], --lzma2[=options] | |||||||||||||||||||||||||||||||||||||||||||||||||
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 doesnt 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:
| |||||||||||||||||||||||||||||||||||||||||||||||||
When decoding raw streams (--format=raw), LZMA2 needs only the value of dict. LZMA1 needs also lc, lp, and pb. | |||||||||||||||||||||||||||||||||||||||||||||||||
--x86[=options]
--powerpc[=options] --ia64[=options] --arm[=options] --armthumb[=options] --sparc[=options] | |||||||||||||||||||||||||||||||||||||||||||||||||
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 doesnt 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 doesnt 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:
| |||||||||||||||||||||||||||||||||||||||||||||||||
Since the BCJ-filtered data is usually compressed with LZMA2, the compression ratio may be improved slightly if the LZMA2 options are set to match the alignment of the selected BCJ filter. For example, with the IA-64 filter, its good to set pb=4 with LZMA2 (2^4=16). The x86 filter is an exception; its usually good to stick to LZMA2s default four-byte alignment when compressing x86 executables. | |||||||||||||||||||||||||||||||||||||||||||||||||
All BCJ filters support the same
options:
| |||||||||||||||||||||||||||||||||||||||||||||||||
--delta[=options] | |||||||||||||||||||||||||||||||||||||||||||||||||
Add Delta filter to the filter chain. The Delta filter can be used only as non-last filter in the 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 give significantly better results than Delta + LZMA2. This is true especially with audio, which compresses faster and better e.g. with FLAC. | |||||||||||||||||||||||||||||||||||||||||||||||||
Supported
options:
| |||||||||||||||||||||||||||||||||||||||||||||||||
Other options
-q, --quiet | |
Suppress warnings and notices. Specify this twice to suppress errors too. This option has no effect on the exit status. That is, even if a warning was suppressed, the exit status to indicate a warning is still used. | |
-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 | |
Dont set the exit status to 2 even if a condition worth a warning was detected. This option doesnt affect the verbosity level, thus both --quiet and --no-warn have to be used to not display warnings and to not alter the exit status. | |
-h, --help | |
Display a help message describing the most commonly used options, and exit successfully. | |
-H, --long-help | |
Display a help message describing all features of xz, and exit successfully | |
-V, --version | |
Display the version number of xz and liblzma. | |
EXIT STATUS
0 | All is good. |
1 | An error occurred. |
2 | Something worth a warning occurred, but no actual errors occurred. |
ENVIRONMENT
XZ_OPT | 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. |
LZMA UTILS COMPATIBILITY
The command line syntax of xz is practically a superset of lzma, unlzma, and lzcat as found from LZMA Utils 4.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 levels
The numbering of the compression level presets is not identical in xz and LZMA Utils. The most important difference is how dictionary sizes are mapped to different presets. Dictionary size is roughly equal to the decompressor memory usage.
Level | xz | LZMA Utils |
-1 | 64 KiB | 64 KiB |
-2 | 512 KiB | 1 MiB |
-3 | 1 MiB | 512 KiB |
-4 | 2 MiB | 1 MiB |
-5 | 4 MiB | 2 MiB |
-6 | 8 MiB | 4 MiB |
-7 | 16 MiB | 8 MiB |
-8 | 32 MiB | 16 MiB |
-9 | 64 MiB | 32 MiB |
The dictionary size differences affect the compressor memory usage too, but there are some other differences between LZMA Utils and XZ Utils, which make the difference even bigger:
Level | xz | LZMA Utils 4.32.x |
-1 | 2 MiB | 2 MiB |
-2 | 5 MiB | 12 MiB |
-3 | 13 MiB | 12 MiB |
-4 | 25 MiB | 16 MiB |
-5 | 48 MiB | 26 MiB |
-6 | 94 MiB | 45 MiB |
-7 | 186 MiB | 83 MiB |
-8 | 370 MiB | 159 MiB |
-9 | 674 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 isnt 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 .lzma format allows lc values up to 8, and lp values up to 4. LZMA Utils can decompress files with any lc and lp, but always creates files with lc=3 and lp=0. Creating files with other lc and lp is possible with xz and with LZMA SDK.
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.
These limitations shouldnt be a problem in practice, since practically all .lzma files have been compressed with settings that liblzma will accept.
Trailing garbage
When decompressing, LZMA Utils silently ignore everything after the first .lzma stream. In most situations, this is a bug. This also means that LZMA Utils dont support decompressing concatenated .lzma files.
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.
NOTES
Compressed output may vary
The exact compressed output produced from the same uncompressed input file may vary between XZ Utils versions even if compression options are identical. This is because the encoder can be improved (faster or better compression) without affecting the file format. The output can vary even between different builds of the same XZ Utils version, if different build options are used or if the endianness of the hardware is different for different builds.
The above means that implementing --rsyncable to create rsyncable .xz files is not going to happen without freezing a part of the encoder implementation, which can then be used with --rsyncable.
Embedded .xz decompressors
Embedded .xz decompressor implementations like XZ Embedded dont 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.
Outside embedded systems, all .xz format decompressors support all the check types, or at least are able to decompress 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.
SEE ALSO
XZ Utils: <http://tukaani.org/xz/> XZ Embedded: <http://tukaani.org/xz/embedded.html> LZMA SDK: <http://7-zip.org/sdk.html>