Compress files with xz
Squeeze logs, dumps and archives smaller than gzip can, with a single flag to keep the originals.
01Command
$ xz -k -9 big.log02What it does
xz (LZMA2) typically beats gzip and bzip2 by a wide margin on text, logs and database dumps, at the cost of slower compression. -k keeps the input file instead of replacing it, and presets -0 to -9 trade speed against size, with -9 getting the last few percent. xz -t verifies an archive without unpacking, and tar -cJf archive.tar.xz dir/ combines both tools.
03Risk
04Undo
$ xz -dk big.log.xz05Sources
- xz(1) — Arch Manual PagesEvidence: Same flags documented: --keep to not delete the input, --decompress, --test, and memory usage of the -9 preset.
- xz(1) — Debian bookwormEvidence: Documents -z/--compress, -d/--decompress, -k/--keep, -t/--test and the -0...-9 preset levels.
Last verified: 2026-09-19 · Category: Files & Folders
06Related solutions
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
rsync copies over SSH, skips unchanged files, resumes interrupted transfers, and preserves permissions and timestamps.