The Wayback Machine - https://web.archive.org/web/20240922031554/https://www.geeksforgeeks.org/how-to-unzip-tgz-file-using-linux/
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.



Similar Reads

How to Extract a TAR file (.tgz) on Windows?
Need to extract a TAR file (.tgz) on your Windows system? TAR files are commonly used for bundling multiple files in Unix-based systems, but you can easily extract them in Windows as well. In this guide, we will show you how to extract TAR files (.tgz) using various tools available on Windows. Our step-by-step instructions will help you quickly and
4 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 files to reduce file size and also used as a file
2 min read
Unzip Command in Linux
As an open-source operating system, Linux presents plenty of powerful and versatile instructions for dealing with files and directories. One such command that performs an important role in coping with compressed files is the "unzip" command. Compressed files are a common way to keep space and share data efficiently. In Linux, the 'unzip' command in
8 min read
How to Unzip (Open) Gz File
If you have been using Linux for some time, you must have come across a "gz" file. Have you ever wondered, what is it and how do you actually open it? Worry not, in this article, we deep dive into the details of gz file and help you overcome your doubts about it. Table of Content What is gz file?How to open gz fileMethod 1: Using the gzip commandMe
7 min read
How to Create a File in the Linux Using the Terminal?
In this article, we will learn to create a file in the Linux/Unix system using the terminal. In the Linux/Unix system, there are the following ways available to creating files. Using the touch commandUsing the cat commandUsing redirection operatorUsing the echo commandUsing the heredocUsing the dd command1. Create a file in the Linux/Unix system us
4 min read
How to copy a file's content from Linux terminal?
This article shows the alternative method to copy the content of the file onto the clipboard, via the Linux terminal. In OSX, the commands pbcopy and pbpaste are available by default. Thus, to copy a file onto the clipboard via OSX terminal, type: pbcopy &lt; &#039;path of the file&#039; Since, in Ubuntu, pbcopy and pbpaste commands are not availab
2 min read
Fzf - File Search From Linux Terminal
Fzf is a command-line general-purpose fuzzy finder tool. It is somewhat like grep. It is a cross-platform command-line tool, that helps you to search and open files quickly. Furthermore, it is open-sourced portable with no dependencies. It has supports for Vim/Neo vim plugin, key bindings, and fuzzy auto-completion. It can be used with any list; fi
3 min read
Creating and Executing a .jar File in Linux Terminal
JAR - Java Archive. It is like a zip file but for java classes. It combines all the .class files in Java into a single .jar file. It is used to download all java classes on HTTP in a single operation. These can be created using the "jar" CLI tool. It also has an optional META-INF which can include files like - MANIFEST.MF - manifest file is used to
3 min read
How to Unzip Files on Android?
Unzipping Files on Android is a simple task to perform nowadays. This can be achieved by using Google Files (a pre-installed app) or by installing ZArchiver or WinZip on your Android smartphone. We're going to explain both of these methods that you can apply while unzipping files on Android. But before that first understand the purpose of zipped fi
4 min read
3 Easy Methods - How to Zip and Unzip Files in Windows 11 Free
ZIP is the process of compressing multiple files and folders into a smaller file known as an archive. This type of compression can significantly reduce both the amount of space required for data storage and the time required to transmit it. Back in '98, Microsoft create­d the zip and unzip option that helps save­ space, even with big file­s. Window
4 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-based storage systems in the control process to im
5 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 Install W3M? As W3M is not included by default on m
1 min read
Using Lynx to Browse the Web From the Linux Terminal
Lynx is a terminal-based web browser for all Linux distributions. It shows the result as plain text on the terminal. It is a classic non-graphical text-mode web browser which displays the pages on the terminal. Lynx does not load images and multimedia contents, hence it is fast as compared to other browsers. One who do not want so many images and m
2 min read
Searching Stack Overflow from Linux Terminal Using SoCLI Tool
SoCLI is a command-line tool written in python used to search queries on the stack overflow. We can search anything on stack overflow using the SoCLI tool without using the terminal. You can search for any question on Stack overflow on the terminal using SoCLI tool. Installation of SoCLI: Let's see how to install the SoCLI tool on Linux. The prereq
4 min read
How to Share Linux Terminal Using Teleconsole?
You already know about many popular remote desktop sharing applications. But this is very different because this is only shared with the terminal, not the full desktop. Here we see how to use teleconsole and how to share your terminal with your friend. Teleconsole is a tool that can allow you to share your Linux terminal with your friend, and they
2 min read
Formatted text in Linux Terminal using Python
This article demonstrates how to print formatted text in Linux terminal using Python programming language. Formatted text(also called styled text or rich text) as opposed to plain text, has styling information like: color (text color, background color), style (bold or italic), and some other special features like Strike-through text, underlined tex
4 min read
How to change the keyboard layout using Kali Linux Terminal
In Kali Linux, altering the keyboard layout can be quite important, particularly when utilizing various languages or layouts. Thankfully, the terminal makes it simple to swap between keyboard layouts. You will be guided step-by-step through the process by this guide. How to change the keyboard layout using Kali Linux TerminalMethod 1: Using setxkbm
4 min read
How to Customize Linux Terminal Using powerlevel10k?
Sometimes we get bored with the normal Linux Terminal and feel like if we can customize the same, so we can use powerlevel10k for that. It is a theme for ZSH. It changes normal shell commands to colorful commands. To install powerlevel10k we need to install Oh My Zsh, both are open-source in GitHub. We can also use nerd font to make the powerlevel1
2 min read
Cool Custom Welcome Messages on Linux terminal
There is a Linux hack which can be used to display a custom message on the terminal every time we open it. This can be done by manipulating the .bashrc shell script. What is .bashrc ? It is a shell script that Bash runs whenever it is started interactively. You can put any command in that file that you could type at the command prompt. Steps on how
3 min read
Custom commands for linux terminal
Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux, the first step is to create a bash script for the command. The second step is to make the command executable. Syntax : $ nano ~/.bashrc Here, bashrc means run the Bash file. Bash is located at /bin/bash . This file helps in c
2 min read
Few Tips for Fast &amp; Productive Work on a Linux Terminal
This article is aimed at making you more productive and waste less time on running commands by providing you the information about Linux Terminal's Shortcut &amp; Tricks. In simple words, less time you take to complete a task the more professional you become! 1. Opening the Linux Terminal (Ubuntu): The Linux terminal can be opened from a window or
4 min read
Shortcut to Move to the Beginning or Ending of a Command in Linux Terminal
In this article, we will learn how to move to the start and end of a command. We will demonstrate the key combinations in a Git terminal. The same key combinations work in other Unix style terminals too. Moving to the Starting of the Command Ctrl + A : The 'Ctrl+A' key combination moves the pointer to the start of the command. In the below gif imag
1 min read
Kali Linux - Terminal and Shell
Generally, operating systems have 2 interfaces GUI(Graphical User Interface) and CLI(Command Line Interface) and the same is the case with Linux Based Operating Systems. Linux Operating Systems are generally packed with terminal emulator packages for CLI based functioning and Desktop environment packages for GUI based functioning. Some common ones
3 min read
Basic System Controls with Terminal in Linux
Sometimes some of the basic services of the system stop working or starts malfunctioning. And it becomes really difficult to solve the problem through Graphical User Interface so here is the list of Terminal Command to solve the problem and to control the basic services manually. Installing the required packages To control the basic system services
2 min read
10 Best Linux Terminal Emulators
Despite various GUI advancements, Terminal Emulators have still an adequate presence in the tech market. A terminal emulator is software that allows to you interact with the host machine with the help of commands. Terminal Emulator is a lifeline for every Linux distro as it enables you to utilize the real strength of Linux. For developers, their ma
7 min read
How to Install Tilix Terminal Emulator in Ubuntu/Fedora/Arch Linux?
A terminal emulator is a software that helps in interacting with the computer machine and perform operations using commands. Tilix is a tiling terminal emulator formerly known as Terminix. It is an enhancement over a regular terminal and provides some important features. Features of Tilix Terminal Emulator: Enable users to split the terminal into d
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 tools for ddgr installation: Python3.3 or later.Python
2 min read
Testing Website Loading Speed in Linux Terminal
We will see How to test a website loading speed in a Linux terminal. Here a website response time (which is getting back the result) will have a great impact on user experience. Because the loading or response is very slow we will be so frustrated. Even if our site has a slow response time the user may get a bad experience. So in this article, we w
3 min read
Linux Fun - Displaying Steam Locomotive on Terminal
Making fun of our mistakes can be a good approach for learning anything smoothly because it gives us a little bit of dopamine release in our mind so this can help us to improve our health and mind as well. Now we will learn about one more mistake while doing some kinds of stuff in our Linux terminal let's do it : You may remember when we are typing
2 min read
AMP Text Editor for Linux Terminal
Amp is a fully-featured and lightweight text editor inspired by the Vi/Vim text editor. Amp editor is a terminal-based editor, and it is written in the Rust language. It provides the all fundamental features required for a modern text editor. Amp does not need any configuration it comes with all configuration, and it does not use any plugins. And i
3 min read