Archives and compression

Command xz

Compress file using xz algorithm

Linux · Bash examples · commands run on the selected server

When to use xz

Use xz when compressing a single stream with a chosen resource tradeoff. Compression settings affect memory and CPU use; preserving the original is useful while validating a newly generated compressed file.

Syntax

xz [OPTIONS] FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-k
Save source.
-d
Unpack .xz.
-T N
Limit the number of threads for supported multithreading.

Usage examples

Compress in one stream

xz -k -T 1 ./report.txt

A compressed copy is created using one compression thread while keeping the source.

Check integrity

xz -t ./report.txt.xz

The compressed stream is tested without creating an extracted file.

Output unpacked text

xz -dc ./report.txt.xz

The decompressed stream is displayed or can be piped to another command.

Notes and limitations

  • High compression levels can require a lot of memory and CPU; choose them taking into account the server.
  • Without -k, the normal operation replaces the original file. For directory tree use tar.

Common questions and troubleshooting

Does single-thread compression limit memory completely?

No. Dictionary and compression settings also determine memory demand. Check the local manual and resource budget for large inputs.

Does an integrity check verify the source's authenticity?

No. A valid stream can still contain unwanted data. Verify a trusted signature or checksum and inspect the intended contents separately.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man xz.