LinuxCommandLibrary

xz

TLDR

Compress a file

$ xz [file]
copy
Decompress a file
$ xz -d [file.xz]
copy
Compress with maximum compression
$ xz -9 [file]
copy
Compress keeping the original file
$ xz -k [file]
copy
Compress to stdout (for piping)
$ xz -c [file] > [file.xz]
copy
Decompress to stdout
$ xz -dc [file.xz]
copy
List compressed file info
$ xz -l [file.xz]
copy
Test compressed file integrity
$ xz -t [file.xz]
copy

SYNOPSIS

xz [options] [file...]

DESCRIPTION

xz is a general-purpose compression tool using the LZMA2 algorithm. It provides high compression ratios, often better than gzip and bzip2, though compression is slower.
By default, xz compresses files and replaces them with .xz versions. Use -k to keep originals or -c to write to stdout for pipelines.
Multi-threading support (-T) significantly speeds up compression on multi-core systems. Decompression is single-threaded but fast.
The compression level affects both ratio and memory usage. Level 9 requires significantly more memory than lower levels, both for compression and decompression.

PARAMETERS

-d, --decompress

Decompress files
-z, --compress
Compress files (default)
-k, --keep
Keep original file
-c, --stdout
Write to stdout, keep original file
-f, --force
Force compression/decompression
-t, --test
Test compressed file integrity
-l, --list
List information about compressed files
-0 to -9
Compression level (0=fast, 9=best compression)
-e, --extreme
More compression (slower)
-T N, --threads=N
Use N threads (0 = auto-detect cores)
-v, --verbose
Verbose output
-q, --quiet
Suppress warnings

CAVEATS

High compression levels (7-9) use substantial memory. Level 9 may require over 600MB for compression and 65MB for decompression.
For archive distribution, consider xz's memory requirements on target systems. Lower compression levels are more universally usable.
xz format is not compatible with gzip or bzip2. Use appropriate tools (gzip, bzip2) for those formats.

SEE ALSO

gzip(1), bzip2(1), zstd(1), tar(1), xzcat(1)

Copied to clipboard