xz(1)
Compress or decompress files using the XZ compression format with high compression ratios.
Synopsis
xz [OPTION]... [FILE]...Description
xz is a general-purpose data compression utility that uses the LZMA2 compression algorithm. It achieves very high compression ratios, often better than gzip or bzip2, though it requires more CPU time and memory. By default, xz compresses files in-place, replacing the original with a .xz compressed version.
If no files are specified, xz reads from standard input and writes to standard output. Multiple files can be compressed or decompressed in a single command. The compression level can be tuned from 0 (fastest) to 9 (best compression).
Common options
| Flag | What it does |
|---|---|
-d, --decompress | Decompress files instead of compressing them |
-k, --keep | Keep input files instead of deleting them after compression/decompression |
-f, --force | Force overwrite of output files and decompress files with unusual suffixes |
-c, --stdout | Write to standard output; keep input files unchanged |
-0 to -9 | Set compression level (0=fastest, 9=best); default is 6 |
-e, --extreme | Use more CPU to improve compression ratio at the cost of speed |
-v, --verbose | Show compression progress and statistics |
-q, --quiet | Suppress warnings and notices |
-l, --list | List information about .xz files (uncompressed size, compression ratio, etc.) |
-t, --test | Test integrity of compressed files without decompressing to disk |
-j NUM, --threads=NUM | Use NUM parallel threads for compression/decompression |
-T NUM | Set maximum number of threads for decompression |
Examples
Compress largefile.tar to largefile.tar.xz, removing the original
xz largefile.tarCompress document.txt with best compression ratio (-9) while keeping the original file
xz -k -9 document.txtDecompress archive.tar.xz back to archive.tar
xz -d archive.tar.xzCompress on stdout and pipe over SSH to decompress on remote host
xz -c largefile | ssh user@host 'xz -d > largefile'Display compression statistics for all .xz files in current directory
xz -l *.xzTest integrity of compressed backup without extracting it
xz -t backup.tar.xzCompress with extreme settings using 4 parallel threads for maximum compression
xz -e -j 4 bigfile.binCreate a tar archive and pipe directly to xz compression, writing to file
tar cf - directory | xz -9 -c > directory.tar.xz