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.
- Open your file manager in Linux.
- Navigate to the folder that contains your tar.gz archive.
- Right-click your archive and select “Extract to.”
- 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
- Open a terminal and go to the directory that holds your tar.gz file.
- 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.
- Install Xarchiver in Debian and Ubuntu by running the following command:
sudo apt install xarchiver
- Run “Xarchiver.” Click “Archive,” then “Open.”
- Navigate to your tar.gz file and click “Open.”
- Click “Action,” then “Extract.”
In the option box that shows up, choose how and where you want to unzip your tar.gz file.
- Click the “Touch files” checkbox. This will tell Xarchiver to unzip the contents of your archive, regardless of the files in the destination directory.
- 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.
- To start installing Unpack, clone the Unpack script from the author’s Git repository:
git clone https://github.com/githaff/unpack.git
- Make a “bin” folder in your user’s home directory:
mkdir /home/$USER/bin
- Copy the Unpack script to your new “bin” folder:
cp /home/$USER/unpack/unpack /home/$USER/bin/
- Enable the execute bit of your new Unpack script:
chmod u+x,go-x /home/$USER/bin/unpack
- 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.
Our latest tutorials delivered straight to your inbox