How to Extract tar xz File in Linux

How to extract xz tar file in linux

In this tutorial, we will look at how you can compress and extract tar xz tarball files/directories with a .tar.xz file extension in Linux.

The xz format is a single-file compression format that is based on the LZMA2 algorithm. It offers lossless compression, implying that it keeps the original data without compromising on its quality. This makes it ideal for shipping software application and image files. The xz compression is much slower but its decompression is quite fast.

Before we begin compressing or uncompressing files, first ensure that xz tools are installed. Newer Linux distributions come with xz tools already installed. However, if xz tools are missing, install using the following commands.

Install xz-utils on Debian/Ubuntu

To install xz tools in Ubuntu and Debian distros, run the command below

sudo apt install xz-utils


install xz-utils

Install xz tool on CentOS/RHEL

For CentOS and RedHat distributions run

yum install xz


yum install xz

Install xz tool on Fedora

For Fedora systems run

dnf install xz


dnf install xz

How to Create xz compressed file

In this example, we are going to compress a directory data containing a few files

mkdir data and create files

To compress the directory, execute the command below

tar -cjcf data.tar.xz data/

You can confirm the creation of a .tar.xz file using the ls command as shown


create tar xz file from a directory

How to extract/unzip xz tar file

To uncompress the xz tarball we just created, execute the command below

tar -xvf data.tar.xz


extract tar xz file

As seen above, the command is the same as extracting a .tar.gz file

How to extract .xz file

To extract .xz file you can use 'unxz' or 'xz' command as below

xz --decompress data.xz


unxz data.xz


This tutorial illustrates how you can proceed to compress and unzip xz tarball files in Linux on the command line. Feel free to try out the commands and let us know how it went. Thanks!

Read Also:

Jamie Arthur 11:49 pm


Your email address will not be published. Required fields are marked *

All comments are subject to moderation.