n this brief guide, 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
Output
Install xz tool on CentOS/RHEL
For CentOS and RedHat distributions run
yum install xz
Output
Install xz tool on Fedora
For Fedora systems run
dnf install xz
Output
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
Output
How to extract/unzip xz tar file
To uncompress the xz tarball we just created, execute the command below
tar -xvf data.tar.xz
Output
As seen above, the command is the same as extracting a .tar.gz
file
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!
Read Also:
- 16 Tar Commands to Compress and Extract Files in Linux