How to Unzip a Tar.gz File in Linux

A photograph of a library with computer desktops.

Tar.gz is one of the most common file compression formats in Linux today. Unlike ZIP, RAR and 7ZIP, it is a combination of two different file formats: TAR and GZIP. This tutorial shows how to unzip a tar.gz file using both graphical and command tools that are already a part of your Linux distribution.

What Is Tar.gz?

A tar.gz file is a combination of tar and gzip. The former encodes your file in a sequential archive format suitable for magnetic tapes, while the latter compresses it to a smaller size.

The biggest advantage of tar.gz files is that they are more compact and easier to handle than other compressed archive formats.

In addition, gzip is a format that is as old as the Internet itself, so tools that can compress and decompress tar.gz files are widely available for almost all platforms.

Unzip Tar.gz Files Using Your File Manager

Most, if not all, of Linux file managers can unzip a tar.gz file. For example, the Nautilus file manager in Ubuntu can unzip tar.gz via the context menu.

  1. Open your file manager in Linux.
  1. Navigate to the folder that contains your tar.gz archive.
A window showing a single tar.gz archive.
  1. Right-click your archive and select “Extract to.”
A screenshot highlighting the "Extract to..." option in Nautilus.
  1. Select the directory in which to save the extracted files. Click “Select.”
A window showing the location where you can unzip the tar.gz file.

Tip: while Gzip is a great tool, it is far from the only one that can do compression on Linux. Learn more about the best compression tools in Linux today.

Unzip Tar.gz Files Using the Command Line

  1. Open a terminal and go to the directory that holds your tar.gz file.
A terminal showing the contents of the Downloads directory.
  1. Unzip your tar.gz file with the tar command:
tar -xzvf maketecheasier.tar.gz
A terminal showing the unzipping process using tar.

You can also tell tar to extract your archive on a different directory. For example, the following command will unzip my “maketecheasier.tar.gz” file to my “Documents” folder:

tar -xzvf maketecheasier.tar.gz -C /home/$USER/Documents
A terminal showing the contents of the Documents folder after unzipping.

Unzip Tar.gz Files with Xarchiver

While the file manager in most distributions can work with tar.gz, there are cases where you need a more powerful tool to do the job. Xarchiver is a highly flexible graphical program that can unzip archives and portable package formats in Linux.

  1. Install Xarchiver in Debian and Ubuntu by running the following command:
sudo apt install xarchiver
A terminal showing the installation process for Xarchiver.
  1. Run “Xarchiver.” Click “Archive,” then “Open.”
A screenshot showing the "Open" button on Xarchiver.
  1. Navigate to your tar.gz file and click “Open.”
A screenshot showing the file picker dialog for Xarchiver.
  1. Click “Action,” then “Extract.”
A screenshot showing the "Extract" option in Xarchiver.

In the option box that shows up, choose how and where you want to unzip your tar.gz file.

A screenshot of Xarchiver's "Extract Files" window.
  1. Click the “Touch files” checkbox. This will tell Xarchiver to unzip the contents of your archive, regardless of the files in the destination directory.
A screenshot highlighting the "Touch files" option on Xarchiver's "Extract files" window.
  1. Click the “Extract” button to unzip your tar.gz file.
A screenshot highlighting the "Extract" button on Xarchiver's "Extract files" window.

Unzip Tar.gz Files with Unpack

Unpack is a simple third-party Bash wrapper script that allows you to unzip almost any type of modern archive format in Linux. Unlike tar and Xarchiver, it aims to be a simple, single command solution to extract Tar.gz files.

  1. To start installing Unpack, clone the Unpack script from the author’s Git repository:
git clone https://github.com/githaff/unpack.git
A terminal showing the cloning process for the Unpack source.
  1. Make a “bin” folder in your user’s home directory:
mkdir /home/$USER/bin
  1. Copy the Unpack script to your new “bin” folder:
cp /home/$USER/unpack/unpack /home/$USER/bin/
  1. Enable the execute bit of your new Unpack script:
chmod u+x,go-x /home/$USER/bin/unpack
A terminal showing the correct permission bits for Unpack.
  1. Use unpack to unzip your tar.gz file. For example, running the following command will extract the “maketecheasier.tar.gz” file on my “Downloads” folder:
unpack /home/$USER/Downloads/maketecheasier.tar.gz
A terminal showing the contents of the Tar.gz file.

Good to know: you can save more disk space in Linux by enabling TRIM for your SSD while compressing your archive files.

Frequently Asked Questions

Is it possible to extract a tar.gz file in macOS and Windows?

You can unzip a tar.gz file in macOS by double-clicking it in the Finder program. You can also use the same tar command to extract the tar.gz file in the Terminal.

To unzip a tar.gz file on Windows, you can either download the 7zip archive utility or install Linux through the WSL.

Is it possible to extract multiple tar.gz files at the same time?

You can unzip multiple tar.gz archives in the same folder by running a Bash for loop inside your archive directory: for i in $(ls); do tar -xvzf $i ; done. You can also use Xarchiver’s Multi-Extract tool to extract multiple tar.gz files.

Can Xarchiver selectively extract tar.gz files instead of overwriting them?

Yes. Uncheck the “Touch files” option on the Extract Files dialog box, then enable either the “Update existing files” option or the “Freshen existing files only” checkbox.

Image credit: Unsplash. All alterations and screenshots by Ramces Red.

Is this post useful?
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.