LinuxCommandLibrary

xz

Compress or decompress '.xz' files

TLDR

Compress a file using xz

$ xz [path/to/file]
copy

Decompress an XZ file
$ xz --decompress [path/to/file.xz]
copy

Compress a file using lzma
$ xz --format=lzma [path/to/file]
copy

Decompress an LZMA file
$ xz --decompress --format=lzma [path/to/file.lzma]
copy

Decompress a file and write to stdout (implies --keep)
$ xz --decompress --stdout [path/to/file.xz]
copy

Compress a file, but don't delete the original
$ xz --keep [path/to/file]
copy

Compress a file using the fastest compression
$ xz -0 [path/to/file]
copy

Compress a file using the best compression
$ xz -9 [path/to/file]
copy

SYNOPSIS

xz [options] [file ...]

PARAMETERS

-z, --compress
    Compress. This is the default operation mode when decompressing isn't specified explicitly.

-d, --decompress, --uncompress
    Decompress.

-l, --list
    List information about xz archives. Shows header, compressed data, and integrity check sizes.

-t, --test
    Test the integrity of compressed files.

-k, --keep
    Keep (don't delete) input files during compression or decompression.

-f, --force
    Force overwrite of output file and (de)compress even if there are multiple files with the same name.

-c, --stdout, --to-stdout
    Write to standard output.

-q, --quiet
    Suppress warnings; specify twice to suppress errors too.

-v, --verbose
    Be verbose. Give details about the compression ratio, etc.

-T, --threads=num
    Specify the number of threads to use (defaults to 1). Larger numbers can speed up compression on multi-core systems.

-0 ... -9
    Compression level. 0 is fastest, 9 is best. Default is 6.

--version
    Display version information and exit.

--help
    Display help and exit.

DESCRIPTION

The xz command is a general-purpose data compression tool, commonly used on Linux systems. It compresses files using the LZMA2 algorithm, which generally provides a higher compression ratio than gzip or bzip2. The primary use of xz is to reduce the size of files for storage and transmission purposes. It can both compress files to create .xz archives, and decompress them to restore the original data. The xz format has gained popularity in packaging and distribution, especially for software packages and large data sets. Understanding how to use xz is crucial for system administrators, developers, and anyone who frequently handles compressed data on Linux and other Unix-like systems. While xz typically operates on files, it can also work with streams, allowing it to be incorporated into pipelines for real-time compression and decompression tasks.

CAVEATS

If the input file has multiple hard links, xz will operate on the first hard link only. The other files pointing to the same underlying data will not be compressed or decompressed.

INTEGRITY CHECKS

xz supports different integrity checks like CRC32, CRC64, and SHA-256 to ensure data integrity. The default check is CRC64.

FILENAME HANDLING

When decompressing a file, xz by default attempts to restore the original filename if it was stored in the archive. The --keep option prevents the original compressed file from being deleted, preserving both the compressed and decompressed versions.

HISTORY

The xz format and command were developed as a replacement for gzip, offering superior compression ratios. It gained prominence as a result of its integration into Linux distributions for package management and system images.

SEE ALSO

gzip(1), bzip2(1), tar(1)

Copied to clipboard