xz Command Examples in Linux

The xz command is a data compression utility, similar to gzip, that reduces the size of selected files and manages files in the .xz file format. The xz command has several options.

Option Used To
-d Decompress a file.
-f Force compression or decompression of a file even if it has multiple links or if the file exists.
-q Suppress all warnings.
-v Display the name and percentage reduction of the compressed or decompressed file.
-t Perform an integrity check on the compressed file.

Syntax

The syntax of the xz command is:

# xz [options] [file names]

xz Command Examples

1. Compress a file to the xz file format:

# xz file

2. Decompress a xz file:

# xz -d file.xz

3. Compress a file to the LZMA file format:

# xz --format=lzma file

4. Decompress an LZMA file:

# xz -d --format=lzma file.lzma

5. Decompress a file and write to stdout:

# xz -dc file.xz

6. Compress a file, but don’t delete the original:

# xz -k file

7. Compress a file using the fastest compression:

# xz -0 file

8. Compress a file using the best compression:

# xz -9 file
Related Post