how to extract Tar files in Linux

How to Extract or Untar a File on Linux

Unzipping files is one of the basic things every operating system out there can do. Each has its own way of doing it and Linux is no different. While you may think unzipping files in Linux might require you to have a degree in rocket science, you’d be wrong and while you could unzip files from the command line, there are lots of GUI apps that can also unzip files with ease. Hence, in this article, let’s look at how to extract or untar ZIP or TAR files on Linux.

Tar and its Types

Before we dig in, it’s important to understand Tar and its types and how they’re used in different scenarios to bundle and pack files in Linux. Tar stands for Tape Archive and the difference between the same and Zip files is Tar bundles files without compressing them whereas Zip files are usually compressed. Here are different types of Tar files:

  • tar.xz (Unix compression)
  • tar.gz (Gzip compression)
  • tar (Regular Tar file: No compression)
  • tar.lz (Lzip compression)
  • tar.lzma (Lzma compression)
  • tar.lzo (Lzop compression)
  • tar.zst (Zstd compression)

Bear in mind, that the ‘no compression’ only goes for files ending with “.tar” Compression methods such as Gzip and Unix compression add another extension to the Tar file like “tar.gz” and “tar.xz,” respectively. There are other compression methods too, but the ones mentioned are the most popular.

Extracting Tar Files in Linux using Terminal

One of the simplest ways to extract files ending with the “Tar” extension is by using the tar command. Here’s an example command that shows you how to use tar to untar a Tar archive on Linux.

tar -xvf "name_of_the_file.tar"

In the above command, the option “x” stands for extract, “f” stands for regular file/archive, and “v” is used to show the files after extraction, also known as verbose. Here’s the Tar command in action.

tar -xvf archive.tar

This should give you the following output and extract the files in the “archive.tar” format.

Extracting a Tar file

Tar supports extracting Unix-compressed files, i.e., files ending with “xz;” whereas in the case of “gz” archives, also known as “Gzip-compressed” files. Therefore, if you want to extract a Tar.xz or Tar.gz file, here’s the syntax of how to do it.

##For tar.xz files

tar -xvf "tar_archive.tar.xz"

##For tar.gz files

tar -xvzf "tar_archive.tar.gz"

For Gzip-compressed files, we can use the “-z” option which lets the tar command know that the user wants to untar a Gzip-compressed file. Here are the examples to extract both xz and gz archives in Linux.

#Example of xz tar archive extraction
tar -xvf archive1.tar.xz
Extracting tar XZ archive
#Example of gz tar archive extraction
tar -xvzf peazip_portable-9.3.0.BSD.GTK2.x86_64.tar.gz
Extracting tar gz archive

Extracting Tar Archives in Linux using a File Manager

File managers in Linux support most archive formats including tar, tar.gz, and tar.xz. Hence, if you’re new to Linux and don’t like using the Terminal, use the default file manager that came with your Linux Distro installation. We’ll be using one called Nautilus which comes bundled with GNOME desktop. Here’s how to untar Tar archives using a File Manager.

1. Open the File Manager and navigate to the location of the archive file you want to extract.

2. In Nautilus, you can either double-click on the archive to extract it there itself or right-click on the archive.

Nautilus extract to option

3. In the context menu, choose “Extract” or “Extract to” and then choose a location you want to extract the archive file.

Extract file to a folder

4. Depending on how big the archive is, extracting the same may take time.

Extract any Archive in Linux using PeaZip

Saturation is a big Linux problem still and if you’re not aware if your default file manager supports extracting Tar files, PeaZip is an easy way to do the same. It’s an open-source application that can extract almost all popular archives including 7z, rar, tar, and zip. PeaZip is available for almost all Linux bases and can also be installed using Flatpak or from the app store of your Linux distro. Here’s how to install it using Flatpak.

sudo flatpak install peazip

Once installed, here’s how to use PeaZip to extract archive files and their contents:

1. Launch PeaZip from the apps menu and go to the location where the archive file you want to extract is located.

2. Right-click on the file you want to extract and click Extract or Extract here.

Peazip Extract option

3. If you want to extract the archive to a particular location, select the location in the output section and click Okay.

PeaZip Extract Location

PeaZip comes with many features like the ability to repair an archive in case it’s corrupt, convert the archive into another archive, and more. On top of everything, it’s free and open-source so you needn’t worry about your files and privacy.

Leave a Reply