Extract .xz files on Linux – CenOS / Ubuntu / Debian

Posted on 175 views

How can I extract .tar.xz or .xz files on my Linux system?. xz is a lossless compression program and file format which incorporates the LZMA/LZMA2 compression algorithms. The XZ format is a single-file compression format and does not offer archiving capabilities.

In this guide, we will see how to extract .xz files on Linux. The process will include the installation of necessary utilities and demonstrates usage with an example.

To extract .xz files on Linux – CentOS / Ubuntu, we need an xz-utils package installed on the system we’re working on. See installation below.

Install xz-utils Package on CentOS / Ubuntu / Debian

Install xz-utils package using the relevant package manager for your Linux and matched package name.

### Ubuntu / Debian ###
sudo apt update
sudo apt install xz-utils

### CentOS / Fedora / RHEL ###
sudo yum -y install xz

Extract .xz files on Linux

After package installation, extract your file using the command:

$ unxz file.xz

or --decompress option of xz:

$ xz --decompress file.xz

Here are supported options.

Usage: unxz [OPTION]... [FILE]...
Compress or decompress FILEs in the .xz format.

  -z, --compress      force compression
  -d, --decompress, --uncompress
                      force decompression
  -t, --test          test compressed file integrity
  -l, --list          list information about .xz files
  -k, --keep          keep (don't delete) input files
  -f, --force         force overwrite of output file and (de)compress links
  -c, --stdout, --to-stdout
                      write to standard output and don't delete input files
  -0 ... -9           compression preset; default is 6; take compressor *and*
                      decompressor memory usage into account before using 7-9!
  -e, --extreme       try to improve compression ratio by using more CPU time;
                      does not affect decompressor memory requirements
  -T, --threads=NUM   use at most NUM threads; the default is 1; set to 0
                      to use as many threads as there are processor cores
  -q, --quiet         suppress warnings; specify twice to suppress errors too
  -v, --verbose       be verbose; specify twice for even more verbose
  -h, --help          display this short help and exit
  -H, --long-help     display the long help (lists also the advanced options)
  -V, --version       display the version number and exit

With no FILE, or when FILE is -, read standard input.

In my case, I have a file fedora-coreos-*-openstack.qcow2.xz. To extract it, I’ll use:

$ unxz -v fedora-coreos-35.20220410.3.1-openstack.x86_64.qcow2.xz
fedora-coreos-35.20220410.3.1-openstack.x86_64.qcow2.xz (1/1)
  100 %     399.9 MiB / 1,555.3 MiB = 0.257    85 MiB/s       0:18      

The .xz file is automatically deleted after decompression.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.