$linuxjunkies
>

xz(1)

Compress or decompress files using the XZ compression format with high compression ratios.

UbuntuDebianFedoraArch

Synopsis

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

Description

xz is a general-purpose data compression utility that uses the LZMA2 compression algorithm. It achieves very high compression ratios, often better than gzip or bzip2, though it requires more CPU time and memory. By default, xz compresses files in-place, replacing the original with a .xz compressed version.

If no files are specified, xz reads from standard input and writes to standard output. Multiple files can be compressed or decompressed in a single command. The compression level can be tuned from 0 (fastest) to 9 (best compression).

Common options

FlagWhat it does
-d, --decompressDecompress files instead of compressing them
-k, --keepKeep input files instead of deleting them after compression/decompression
-f, --forceForce overwrite of output files and decompress files with unusual suffixes
-c, --stdoutWrite to standard output; keep input files unchanged
-0 to -9Set compression level (0=fastest, 9=best); default is 6
-e, --extremeUse more CPU to improve compression ratio at the cost of speed
-v, --verboseShow compression progress and statistics
-q, --quietSuppress warnings and notices
-l, --listList information about .xz files (uncompressed size, compression ratio, etc.)
-t, --testTest integrity of compressed files without decompressing to disk
-j NUM, --threads=NUMUse NUM parallel threads for compression/decompression
-T NUMSet maximum number of threads for decompression

Examples

Compress largefile.tar to largefile.tar.xz, removing the original

xz largefile.tar

Compress document.txt with best compression ratio (-9) while keeping the original file

xz -k -9 document.txt

Decompress archive.tar.xz back to archive.tar

xz -d archive.tar.xz

Compress on stdout and pipe over SSH to decompress on remote host

xz -c largefile | ssh user@host 'xz -d > largefile'

Display compression statistics for all .xz files in current directory

xz -l *.xz

Test integrity of compressed backup without extracting it

xz -t backup.tar.xz

Compress with extreme settings using 4 parallel threads for maximum compression

xz -e -j 4 bigfile.bin

Create a tar archive and pipe directly to xz compression, writing to file

tar cf - directory | xz -9 -c > directory.tar.xz

Related commands