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
    user

    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 ~/Downloads
    $ ls
    archive.xz  archive.tar.xz
  3. Confirm that the target file is an xz-compressed archive.
    $ file archive.xz
    archive.xz: XZ compressed data

    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
    archive.xz
    $ unxz archive.xz
    $ ls
    archive

    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 archive.tar.xz --xz
    ./
    ./file1
    ./dir/
    ./dir/file2
    ##### snipped #####

    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
    archive  archive.tar.xz  dir  file1

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

Discuss the article:

Comment anonymously. Login not required.