๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก Compression & Archives September 9, 2026 4

Linux Command: xz

Compress files using LZMA2 algorithm (best compression)

Terminal โ€” Compression & Archives
Command
$ xz large_backup.tar

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.tar

Parallel compression

xz -T$(nproc) -9 huge_file.tar

Decompress

xz -d archive.tar.xz

Pro 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 โ†’

Share this tip