n this brief guide, we will look at how you can compress and extract tar xz tarball files/directories with a
.tar.xzfile 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 tool on CentOS/RHEL
For CentOS and RedHat distributions run
yum install xz
Install xz tool on Fedora
For Fedora systems run
dnf install xz
How to Create xz compressed file
In this example, we are going to compress a directory
data containing a few 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
How to extract/unzip xz tar file
To uncompress the xz tarball we just created, execute the command below
tar -xvf data.tar.xz
As seen above, the command is the same as extracting a
This short article 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!
- 16 Tar Commands to Compress and Extract Files in Linux