How to Extract tar xz File in Linux

Channel: Linux
Abstract: install using the following commands. How to unzip zip files in Linux To view this video please enable JavaScriptand consider upgrading to a web brows

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.

How to unzip zip files in Linux

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

How to unzip zip files in Linux

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

How to extract .xz file

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

xz --decompress data.xz

or

unxz data.xz
Conclusion

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:
  • 16 Tar Commands to Compress and Extract Files in Linux

Ref From: linoxide

Related articles