Linux Commands

How to Uncompress Tar.xz Files?

Tar.xz is a compressed data file type capable of storing data of multiple types and from various applications. It is similar to other compressed file types such as RAR or ZIP but is better and more efficient in data organization.

Tar.xz is not regularly used because it is comparatively complex. It is generally used by IT specialists who have to keep track of multiple variables and are familiar with the functions of Tar.xz.

However, Tar.xz is the prepotent compressed file type used in Linux and its distros. It is dominantly used for compressing package files and kernel archives. To read and write Tar.xz files on Linux, there is the provision of the XZ-utils, which are a set of commands users can use to either compress or uncompress, read and write data on Tar.xz files.

If you are wondering how to deal with the Tar.xz files on your Linux system, you have come to the right place as we will be discussing how to uncompress data present on Tar.xz files with additional tutorials on how to perform the basic actions usually performed on Tar.xz files.

Installing XZ-Utils on Your Linux System.

Before we discuss how to access Tar.xz files, you need to make sure that you have the main tool that you would need to fiddle around with them. As mentioned before, XZ-utils are the main set of commands which you will be using, so let’s take a look at how to get this tool on your system.

Closely follow these steps to successfully install XZ-utils on your system.

Start by opening the Command Terminal. Once opened, type in the following command.

$ sudo apt install xz-utils

You should see that the installation process starts, and when it is completed, you have the XZ-utils on your system.

Compressing and Uncompressing Tar.xz Files.

Compressing files to the Tar.xz format means that you are reducing the size of the file without affecting the quality of the files. After the size of the files has been reduced, the files are stored in a compressed file of the format of Tar.xz.

It’s the opposite when you uncompress a Tar.xz file; we extract the contents of the file and get the required original files in their true uncompressed size. Both compressing and uncompressing require two different types of XZ commands. Let’s have a look at them.

For compressing files, we use the XZ-utils with the following syntax.

$ xz -v -z filename.extension/type

In the above command, -z is the operator instructing the system to compress the file to Tar.xz format.

For uncompressing files, we use the following syntax.

$ xz -v -d filename.Tar.xz

In this command, -d is the operator instructing that the file needs to be uncompressed. Next, we go step-by-step while showing examples of compressing and uncompressing files on the Command Terminal.

First, open the Command Terminal. To compress a file xyz.txt, we will type the following command.

$ xz -v -z xyz.txt

Alternatively, we can also use a modified version of the above-written command.

$ xz xyx.txt

Both these commands perform the same task. Upon execution, xyz.txt has been converted to xyz.txt.xz.

Now, we will decompress the same file we just compressed.

$ xz -v -d xyz.txt.xz

Upon execution of this command, the file has been uncompressed to xyz.txt.

These are the commands you can use to compress files to Tar.xz and uncompress them to retrieve the files.

Extracting Files From a Tar.xz Compressed Folder.

The whole point of having compressed folders is to make the data transfer more efficient with reduced file sizes. Extracting original files is the most commonly performed function on compressed folders, and extraction of specific files from Tar.xz can be done using the following command.

$ tar -xf filename.Tar.xz filename.extension/type

We don’t use the XZ-utils for extraction as there is already an inbuilt provision of the $tar command which allows users to execute basic tasks on Tar.xz files. Next, we will be showing you examples of how you can extract files from a Tar.xz file. Follow these steps to extract the file you want to from the Tar.xz folder.

Open the Command Terminal. We will be extracting the xyz file from our Tar.xz file. Use the following command as a template for your file extraction.

$ tar -xf textfiles.Tar.xz xyz.txt

Upon execution of this command, we will retrieve the file and be able to access it for our needs.

You can also extract all the files present in a Tar.xz file with a single command. You can use $tar in the following way.

$ tar -xf filename.Tar.xz

All the files present in Tar.xz will automatically be extracted to your computer upon execution.

Listing the Contents of a Tar.xz File.

You can also use $tar to view all the contents present in a Tar.xz file without extracting them. This can be useful in detecting spam and preventing your system from malware. Use the following command to list all the contents of your Tar.xz file.

$ tar -tf filename.Tar.xz

All the content of the respective file will be displayed in a listed form as your output.

Conclusion

This was a guide to all the basic functions that can be performed on Tar.xz files. We went through the commands that you can use to compress and uncompress Tar.xz files. Next, we looked at how you can extract all the Tar.xz file contents and how you can extract a specific file from the respective Tar.xz file. We also gave you an intro of Tar.xz files and the commands/tools you can use to access them. We hope that we can help you out, and now you can work with the Tar.xz files.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer by degree, Blogger by skills who loves to write about tech, develop websites & do SEO. You can reach out to me on LinkedIn.