xz-compressed archives are common when downloading source packages, kernel releases, and large logs on Linux systems. Extracting these archives restores the original files so they can be compiled, inspected, or backed up in an uncompressed form.

The xz format compresses a single data stream, while combining it with tar produces multi-file tar.xz archives. On Linux, plain file.xz streams are typically decompressed with unxz, and tar.xz archives are unpacked with tar, which can invoke the xz filter transparently.

Because xz uses strong compression, extraction can be CPU-intensive and requires enough free space for the uncompressed data. The procedure below assumes shell access on a Linux system with tar and xz-utils available and focuses on safely unpacking both single-file xz streams and multi-file tar.xz archives.

Steps to extract xz files in Linux:

  1. Open a terminal on the Linux system where the archive is stored.
    $ whoami
    root

    Any terminal emulator, such as GNOME Terminal or Konsole, can be used.

  2. Change to the directory that contains the .xz or tar.xz archive.
    $ cd /root/sg-work/archives
    $ ls
    destination
    single.txt.xz
    source
    source.7z
    source.tar.bz2
    source.tar.gz
    source.tar.xz
    target
    target-7z
    target-xz
  3. Confirm that the target file is an xz-compressed archive.
    $ file single.txt.xz
    single.txt.xz: XZ compressed data, checksum CRC64

    The file command helps avoid running extraction tools on an unexpected format.

  4. Decompress a single-file archive.xz to its original form using unxz.
    $ ls
    destination
    single.txt.xz
    source
    source.7z
    source.tar.bz2
    source.tar.gz
    source.tar.xz
    target
    target-7z
    target-xz
    $ unxz single.txt.xz
    $ ls
    destination
    single.txt
    source
    source.7z
    source.tar.bz2
    source.tar.gz
    source.tar.xz
    target
    target-7z
    target-xz

    Decompression replaces archive.xz with the uncompressed archive file; keep a backup copy beforehand if the compressed version must be retained.

  5. Extract a tar.xz archive in the current directory using tar with the xz filter.
    $ tar --extract --verbose --file source.tar.xz --xz --directory=target-xz
    source/
    source/alpha.txt
    source/reports/
    source/reports/report.txt
    source/beta.log

    The xz filter is automatically selected on many systems, but the --xz option explicitly tells tar to use xz for decompression.

  6. Verify that the expected files and directories are present after extraction.
    $ ls target-xz
    source

    Listing the directory or running tar -tf archive.tar.xz before extraction helps confirm the archive contents.