Open In App

How to Unzip .tgz File Using the Linux Terminal?

Last Updated : 08 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

If you’re new to Linux, you might find yourself faced with files that have the `.tgz` extension. These files are archives that have been compressed using the tar and gzip utilities. Don’t worry if this sounds complicated! In this guide, we’ll show you how to easily unzip `.tgz` files using two different methods: the `tar` command and the `gunzip` command. By the end of this tutorial, you’ll be able to extract the contents of .tgz files with confidence.

Understanding .tgz or .tar.gz Files

Before we dive into the extraction process, let’s take a moment to understand what `.tgz` files are. A `.tgz` file is essentially a tar archive that has been compressed using gzip compression. Tar archives are used to combine multiple files into a single file, while gzip compression reduces the size of the tar archive, making it easier to store and transfer over the internet.

Quick Highlights On TGZ File Format:

  • 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?

To Unzip .tar.gz File in Ubuntu, the following methods should be performed on the Linux Terminal. We will start with the best & highly used command to Decompress TGZ File.

Open the Terminal (Ctrl + Alt + T)

Open the terminal on your Linux system. You can do this by searching for “Terminal” in your application menu or by using the keyboard shortcut `Ctrl + Alt + T`

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

3. How to Extract the Contents of .tgz File?

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.

1--TAR-Command

Hooray! You have successfully Extracted TGZ Files on the Linux Terminal with the best Unzipping TAR Command.

4. How to Extract File to a Specify Directory?

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>

2--GZIP-Command

Replace `tgz file name` with the name of your `.tgz` file. This command will decompress the `.tgz` file and remove the original `.tgz` file.

3. How to Extract the tar Archive?

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

In this article, we discussed How to Unzip .tgz File Using the Linux Terminal which is an essential skill for beginners. These files, which are tar archives compressed using gzip, can be easily extracted using the tar command or the gunzip command in the terminal.

By following the step-by-step instructions provided in this guide, you’ll be able to extract the content of .tar.gz files with confidence. Whether you choose to use the tar command’s versatility or the simplicity of the gunzip command, you’ll find that unzipping .tgz files on Linux is a straightforward process that opens up a world of possibilities for accessing and managing compressed files.

Also Read

Frequently Asked Questions to unzip .tgz file using the Linux Terminal

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.

  1. Open Linux Terminal.
  2. Execute the command tar -cvzf <file name>.tar.gz <path to file>

Is there any third-party application available to unzip TGZ Files?

Yes, there are many third-party applications present to unzip TGZ files. Also, there are many online converters present that can unzip the TGZ Files online without installing any application. You can use the Chrome Extensions to convert uploaded TGZ Files easily.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads