How to Unzip a Tar.gz File in Linux

Spread the love

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.

Content

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.

  1. Right-click your archive and select “Extract to.”

  1. Select the directory in which to save the extracted files. Click “Select.”

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.

  1. Unzip your tar.gz file with the tar command:
tar -xzvf maketecheasier.tar.gz

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

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

  1. Run “Xarchiver.” Click “Archive,” then “Open.”

  1. Navigate to your tar.gz file and click “Open.”

  1. Click “Action,” then “Extract.”

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

  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.

  1. Click the “Extract” button to unzip your tar.gz file.

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

  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

  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

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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


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.

Comments (1)