How to Unzip .tgz File Using the Linux Terminal?
Last Updated :
18 Sep, 2024
If you’ve come across a .tgz file and are unsure how to access its contents, you’re not alone. Knowing how to extract or unzip a .tgz file in a Linux environment can be highly useful, especially when handling compressed files for software installations, backups, or data transfers. Here, we will walk you through the steps to easily unzip .tgz files using the Linux terminal, ensuring you can access the contents quickly and efficiently.
What is a '.tgz' or '.tar.gz' File?
A `.tgz`
file is essentially a tar archive that has been compressed using gzip compression. It combines two formats:
- TAR (Tape Archive): This format bundles multiple files together into one archive. Think of it as a way to package files.
- GZIP: This is a compression algorithm applied to reduce the size of the '.tar' file.
The '.tgz' or '.tar.gz' extension denotes that the file is a TAR archive that has been compressed using GZIP. This combination helps in reducing the overall file size, making it easier to store or transfer.
- TGZ File is the extensive version of the TAR File Format.
- TGZ File Format comes from the expression tar.gz
- The TGZ Files are created first by converting them to TAR files and then compressed to ZIP.
- TGZ Files are also known as the Tarballs.
- Linux can read specific commands in TGZ Files.
How to Unzip .tgz File Using Linux Terminal?
Extracting .tgz files in Linux is easy once you know the right commands. The most common method involves using the tar command, but you can also use gunzip if needed. Here’s a step-by-step guide for both methods:
Method 1: Unzip .tgz File Using the tar Command
The tar
command is a versatile utility that is used to manipulate archives. To unzip .tar.gz
file using `tar`
command. You can extract .tgz file in following ways.
1. How to Navigate to the Directory Containing the .tgz File?
Use the cd
command to navigate to the directory where your .tgz
file is located. For example, if your file is in the Downloads folder, you would use:
cd Downloads
2. How to View the Contents of the .tgz File?
Before extracting the contents of the `.tgz`
file, you can view its contents using the following command:
tar -ztvf yourfile.tgz
Replace `yourfile.tgz`
with the name of your `.tgz`
file. This command will list the contents of the archive without extracting them
To extract the content of .tar.gz
file, use the following command:
tar -xvzf <tgz file name>
Replace `tgz file name` with the name of your `.tgz`
file. This command will extract the contents of the archive into the current directory.

You have successfully Extracted TGZ Files on the Linux Terminal with the best Unzipping TAR Command.
If you want to extract the contents of .tar.gz
file into a specific directory, you can use the `-C`
option followed by the path to the directory. For example, to extract .tgz file into a directory named `myfolder`
in your current directory, you would use:
tar -xzvf yourfile.tgz -C myfolder
Also Check: How to Compress and Extract Files Using the tar Command on Linux?
Method 2: Unzip .tgz File Using the gunzip
Command
The `gunzip
`
command is used to decompress files that have been compressed using the gzip utility. Here's how you can use it to unzip .tar.gz
file.
1. How to Navigate to the Directory Containing the .tgz File?
Use the cd
command to navigate to the directory where your .tgz
file is located. For example, if your file is in the Downloads folder, you would use:
cd Downloads
2. How to Unzip the .tgz File Using gzip Command?
To unzip the `.tgz`
file, use the following command:
gzip -d <tgz file name>

Replace `tgz file name` with the name of your `.tgz`
file. This command will decompress the `.tgz`
file and remove the original `.tgz`
file.
Once the `.tgz`
file is decompressed, you will have a `.tar`
file. You can extract the contents of .tar.gz
archive file using the tar
command:
tar -xvf yourfile.tar
Replace `yourfile.tar`
with the name of your `.tar`
file. This command will extract the contents of .tgz
archive into the current directory.
So, these are the direct commands that can Decompress TGZ File Format on the Terminal. You can use any of the commands to Unzip TGZ File on Linux Terminal. Just put the entire TGZ File Format Name along with the TGZ File Extension to get your job done. Otherwise, it can cause issues with the Open Linux TGZ File on Terminal.
Conclusion
Unzipping a .tgz file on Linux is a straightforward process once you know the right commands. By following the above mentioned steps, you can quickly and efficiently extract .tgz files using the Linux terminal, saving time and avoiding potential errors. Whether you're handling backups, software packages, or any other type of compressed file, mastering this skill will make your Linux experience much smoother.
Also Read
How to unzip .tgz file using the Linux Terminal - FAQ's
What command do I use to unzip a .tgz file?
The primary command to extract .tgz file is
tar -xvzf <filename.tgz>
Explanation:
tar
: The main utility for manipulating archives.x
: Indicates extraction instead of creation.v
: Enables verbose output, showing what's being extracted.z
: Instructs tar
to use gzip decompression, as .tgz
is typically a gzipped tar archive.<filename.tgz>
: Replace with the actual name of your .tgz file.
How do I unzip the file to a specific directory?
Use the `-C`
flag to specify the target directory: `tar -xvzf <filename.tgz> -C <target_directory>`
.
Example: `tar -xvzf example.tgz -C /home/user/extracted_files`
extracts the content to the `/home/user/extracted_files`
directory.
Are there alternatives to the tar
command?
While `tar`
is comprehensive, consider:
`gzip -d <filename.tgz>`
to decompress only (followed by `tar -xf`
to extract).- GUI tools like `
file-roller`
or `Ark`
for visual extraction.
How to zip TGZ File on Linux Terminal?
To Zip TGZ Files on Linux Terminal with a simple command, the following steps should be used.
- Open Linux Terminal.
- Execute the command tar -cvzf <file name>.tar.gz <path to file>
What is the difference between .tgz and .tar.gz files?
A .tgz file is simply a compressed .tar.gz file, where the tarball (a collection of files) has been compressed using gzip. The steps to unzip a .tgz file on Linux are the same as for a .tar.gz file.
Similar Reads
How to Unzip .tgz File Using the Linux Terminal?
If youâve come across a .tgz file and are unsure how to access its contents, youâre not alone. Knowing how to extract or unzip a .tgz file in a Linux environment can be highly useful, especially when handling compressed files for software installations, backups, or data transfers. Here, we will walk
6 min read
How to Browse From the Linux Terminal Using W3M?
W3M is an open-source text-based terminal web browser for Linux used to browse through the terminal. It is simple to use and do not require any additional interacting interface application though it interacts through the terminal. It renders the web pages in a form as their original layout. How to I
1 min read
How to unzip a file using PHP ?
To unzip a file with PHP, we can use the ZipArchive class. ZipArchive is a simple utility class for zipping and unzipping files. We don't require any extra additional plugins for working with zip files. ZipArchive class provides us a facility to create a zip file or to extract the existing zip file.
2 min read
How to Read Zip Files into R
In the R Programming Language Zip files are compressed archives that store one or more files or directories in compressed format. They are commonly used to package and distribute files, particularly when working with huge datasets or many files. Zip files not only conserve disc space but also facili
4 min read
How to uncompress a ".tar.gz" file using Python ?
.tar.gz files are made by the combination of TAR packaging followed by a GNU zip (gzip) compression. These files are commonly used in Unix/Linux based system as packages or installers. In order to read or extract these files, we have to first decompress these files and after that expand them with th
2 min read
How to Install Zip and Unzip in Linux?
Zip is a command-line compression utility for files and directories. File and folder compression allows for quicker and more reliable file and folder transfer, storage, and email. Unzip, on the other hand, is a program that allows you to decompress files and directories. zip is used to compress the
2 min read
How to Unzip Files on Windows and Mac?
The useful data from a particular file, several files, or a specific folder is compressed using ZIP files and stored in a single, smaller storage unit as per requirement. Data compression speeds up data interchange via email and text messaging while also improving the performance of local and cloud-
5 min read
How to Unpack a PKL File in Python
Unpacking a PKL file in Python is a straightforward process using the pickle module. It allows you to easily save and load complex Python objects, making it a useful tool for many applications, especially in data science and machine learning. However, always be cautious about the security implicatio
3 min read
How to Search DuckDuckGo from the Linux Terminal?
DuckDuckGo is a search engine like Google, but it takes more care about user search protecting its privacy. To search from a terminal there is one tool called ddgr. This tool provides us the ability to search from the terminal by using the DuckDuckGo search engine. Installation of ddgr Required tool
2 min read
Create Desktop Shortcuts Using The Terminal on Ubuntu
Ubuntu is the most popular Linux distribution based on Debian. Linux is always tricky to use. We can easily create a Desktop shortcut for our files, folders, and installed software easily on Windows or Mac but on Ubuntu, it needs some work. In this article, we are going to discuss how to create a de
2 min read