xz

High-ratio compression using the XZ/LZMA algorithm.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

xz provides high compression ratios using the LZMA2 algorithm — better compression than gzip at the cost of more CPU and memory. Widely used for distributing Linux kernel tarballs and large datasets. Works like gzip in its pipeline behavior.

Common flags
FlagMeaning
-d --decompressDecompress
-k --keepKeep input file after compression
-9Maximum compression level
--threads --threadsNumber of threads (0 = all CPUs)
Examples
xz -k large-dataset.tarCompress keeping original file · explain & risk-check →
xz -d archive.tar.xzDecompress xz archive · explain & risk-check →
tar -cJf archive.tar.xz /data/Create xz-compressed tar archive · explain & risk-check →
xz -T 0 -k bigfileCompress using all CPU cores · explain & risk-check →
Pro tip

Use `xz -T 0` to enable multi-threaded compression on large files — xz is single-threaded by default and can be extremely slow without this flag.

Related
tar gzip zstd
Open the full explainer →More in Files & Archives

Reference text is hand-written and may be incomplete — check man xz for your version. Test destructive commands on a non-production system first.