Linux Command: xz
Compress files using LZMA2 algorithm (best compression)
xz compresses files using the LZMA2 algorithm, providing the best compression ratios of the common Linux compression tools. xz-compressed files use the .xz extension. xz produces significantly smaller files than gzip or bzip2, but at the cost of higher CPU usage and longer compression time. Decompression is relatively fast. xz is the standard for Linux kernel source distribution. xz is ideal for archival storage, software distribution, and any case where minimizing file size is the priority.
Syntax
xz [OPTION]... [FILE]...Key Options
-dโ Decompress-kโ Keep original file-0 to -9โ Compression level (0=fast, 9=best)-Tโ Number of threads-vโ Verbose-cโ Write to stdout
Examples
Compress a file
xz large_backup.tarParallel compression
xz -T$(nproc) -9 huge_file.tarDecompress
xz -d archive.tar.xzPro Tips
- xz -T0 uses all available cores. This dramatically speeds up compression: xz -T0 -9 large_file.
- xz typically compresses 20-30% better than gzip and 10% better than bzip2, at the cost of speed.
- xz -9 uses significant memory (~674MB). Lower levels use less. Ensure sufficient RAM for the chosen level.
Learn more: Full xz reference โ