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:
- Open a terminal on the Linux system where the archive is stored.
$ whoami userAny terminal emulator, such as GNOME Terminal or Konsole, can be used.
- Change to the directory that contains the .xz or tar.xz archive.
$ cd ~/Downloads $ ls archive.xz archive.tar.xz
- Confirm that the target file is an xz-compressed archive.
$ file archive.xz archive.xz: XZ compressed dataThe file command helps avoid running extraction tools on an unexpected format.
- 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.
- 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.
- 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.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
