Skip to main content

xz

The xz command is a data compression utility with a high compression ratio. It generally yields better compression than gzip or bzip2, but can take longer and use more memory to compress.

Basic Syntax

xz [OPTION]... [FILE]...

Common Options

OptionDescription
-d, --decompressDecompress files (equivalent to unxz).
-k, --keepKeep (don't delete) input files.
-z, --compressForce compression (default).
-1 to -9Compression preset (default is -6).
-T threads, --threads=threadsSpecify the number of worker threads to use.

Real-world Examples

  1. Compress a file (replaces file with file.xz):

    xz large_database.sql
  2. Compress a file and keep the original:

    xz -k large_database.sql
  3. Decompress an .xz file:

    xz -d archive.tar.xz

    (Alternatively, use unxz archive.tar.xz)

  4. Compress using multiple threads to speed up the process:

    xz -T 4 large_file.bin