How Do I Extract tar.xz in Ubuntu 22.04?

How to Extract Unzip tar.gz Files From Linux Command

In Ubuntu and other distros, files are compressed to reduce storage space consumption. Compressed or zipped files make it easy to transfer files at high speed. Once transferred or stored, these compressed files (in many cases the “tar.xz” files), need to be extracted so that users can access the data or files inside.

This article explains how you can extract “tar.xz” files in Ubuntu.

How do I Extract tar.xz in Ubuntu 22.04?

The “tar.xz” files are easily extracted in Ubuntu System using the “tar” command which is a built-in command in Ubuntu to manage the file system. Below are the steps explained to extract the “tar.xz” file in Ubuntu.

Step 1: Open Terminal

Open the terminal in Ubuntu using the GUI. Hover your mouse pointer over the “Show Applications” icon and then click on it:

The Applications Menu opens and on the top of the screen, you will see the Search Bar. Search for the application you want to filter. In our case, we will search for “Terminal”:

Click on the Terminal to Open it:

You can also use the shortcut key “ctrl+alt+t” to open the Terminal Directly:

Step 2: Navigate to the File Directory

Navigate to the directory having the “tar.xz” file using the “cd” command:

cd <directory>

In our case, the “tar.xz” file is located in the Downloads folder:

To navigate to the Downloads Directory from the Terminal, the cd command will be:

cd Downloads

The command line will now have the Downloads path meaning the Directory is accessed:

The “ls” command can be used to list the files and folders in the directory. To confirm if the command line moved to the Downloads path, use the ls command:


This will list the files in the Downloads Directory and you can see the “tar.xz” file:

Step 3: Extract the “tar.xz” File

Once you are in the directory, you can use the “tar” command to extract the files inside the same directory:

tar -xf <fileName>

In our case, the file name is “tarred.tar.xz”. To extract the “tarred.tar.xz” file, use the command:

tar -xf tarred.tar.xz

The “-xf” flag is used to extract the files of the same archive. The “tarred.tar.xz” file will be extracted and the extracted files will now be available in the same directory, in our case, the “fileA.txt” and the “fileB.txt”:

Extracting a Specific File from the Tar File

To extract only a single or specific file using the “tar” command, the command used will be:

tar <options> <tar-file> <file-to-extract>

In our case, to extract only the “fileA.txt” from the “tarred.tar.xz” file, the command used will be:

tar -xf tarred.tar.xz fileA.txt

This will only extract the “fileA.txt” from the “tarred.tar.xz” file instead of extracting all the files:

Bonus Step: Untar or Compress the Files

The “tar” command can also be used to Compress or untar files and directories. To Compress files or directories the command used is:

tar <tar.xz-fileName> <files/folder-to-compress>

In our case, we have the “fileA.txt” and folder “Hello” inside the Downloads Directory:

To compress the “fileA.txt” and the folder “Hello” into a “tar.xz” file, the tar command will be:

sudo tar cfj Compr.tar.xz fileA.txt Hello

The “cfj” command will create a new archive file. The new “Compr.tar.xz” file will be created and it will compress the “fileA.txt” and “Hello” inside it:

That’s all about extracting tar.xz in Ubuntu 22.04.


The “tar” command is a useful way of extracting files in Ubuntu. It can be used to extract multiple files inside the “tar.xz” file or can extract specific files as well according to the user’s requirements. The “tar” command can compress files as well into a “tar.xz” file. This article explained the different methods to extract “tar.xz” files and also to compress files into a “tar.xz” file.

Similar Posts