Open In App

How to Unzip .tgz File Using the Linux Terminal?

Last Updated : 18 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

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?

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

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

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

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.


Next Article

Similar Reads

three90RightbarBannerImg
  翻译: