What is tgz file? How to open tgz File?

First, we need to understand what a .tgz extension is before we learn how to open the .tgz file. gZip tool is using the .tgz extension to compress a bundle of files. Web applications with millions of customers usually produce tons of logs on a daily basis. Not only log files, but there are other data files required to be stored on the servers. Mostly, these types of applications are deployed on Linux / UNIX platforms. 

What is TGZ File?

Tgz is a compression format mainly used in Linux and Unix platforms. When high volume data files such as logs, scripts, images and other types of code files or packages located on Linux platforms are usually backed up. These backups are stored in a compressed manner. Compressed files reduce the size and more files can be stored on the backup server. Whenever these files are compressed, it creates TGZ format on Linux and Unix platforms. 

As a part of the tech support process, if the ticket request is made to the DevOps team to share the logs for debugging the issue, TGZ files are shared by them. gZip tool generates the .tgz file by default for compression. The tool is similar to WinZip, but is built for UNIX and Linux platforms. 
As part of the application development process, the development team uses .tgz extensions for packages and libraries to be shared with team members. Usually, the application development environment is built on Ubuntu, Linux or Mac platforms. Very easy to extract .tgz extensions on these platforms.

As part of the network monitoring process, the network team uses .tgz extensions to share the server files to vendors or service providers in case there is a request to share network logs from third-party vendors and service providers.

For server administration, the backup and restore process is very important. Whenever there is a request from the business team to restore some historic data, the backups with .tgz files are used to restore the specific data. Easy to extract the backup files as they are labelled logically. Extraction is faster to pick a file and unpack to restore the data.

gZip archive mechanism is used to extract the files with .tgz extensions.

Now, let us understand how to unzip, extract or unpack .tgz files in different operating system platforms.

How to open tgz file in Linux?

Before we see how to extract the tgz file, let us understand the file formats that are the same as tgz. The file formats, “.tar.Z”, “.tar.gz”, and “.tar.bz2” or tgz work the same way for extraction. All these compression formats are usually found in the Unix, Linux/Ubuntu platforms. 

  1. Open terminal in your Linux system.
  2. Enter the command as the text in yellow. Press ENTER.
abosultesys:/tmp$ tar -zxvf logs.tgz
  1. The extraction process is shown as below.
abosultesys:/tmp$ tar -zxvf logs.tgz
etc/PMGaugeEvent-12oct2020.log
etc/PMGaugeEvent-11oct2020.log
etc/PMGaugeEvent-10oct2020.log
etc/PMGaugeEvent-9oct2020.log
etc/PMGaugeEvent-8oct2020.log
etc/PMGaugeEvent-7oct2020.log
etc/PMGaugeEvent-6oct2020.log
etc/PMGaugeEvent-5oct2020.log
etc/PMGaugeEvent-4oct2020.log
etc/PMGaugeEvent-3oct2020.log
etc/PMGaugeEvent-2oct2020.log
etc/PMGaugeEvent-1oct2020.log
etc/PMGaugeEvent-30sep2020.log
etc/PMGaugeEvent-29sep2020.log
etc/PMGaugeEvent-28sep2020.log
etc/PMGaugeEvent-27sep2020.log
etc/PMGaugeEvent-26sep2020.log
etc/PMGaugeEvent-25sep2020.log
etc/PMGaugeEvent-24sep2020.log
etc/PMGaugeEvent-23sep2020.log
etc/PMGaugeEvent-22sep2020.log
etc/PMGaugeEvent-21sep2020.log
etc/PMGaugeEvent-20sep2020.log
etc/PMGaugeEvent-19sep2020.log
etc/PMGaugeEvent-18sep2020.log
etc/PMGaugeEvent-17sep2020.log
etc/PMGaugeEvent-16sep2020.log
etc/PMGaugeEvent-15sep2020.log
etc/PMGaugeEvent-14sep2020.log
etc/PMGaugeEvent-13sep2020.log
etc/PMGaugeEvent-12sep2020.log
etc/PMGaugeEvent-11sep2020.log
etc/PMGaugeEvent-10sep2020.log
abosultesys:/tmp$
  1. Once extracted, you will the text abosultesys:/tmp$.

Let us understand the list of tar commands and flags that are used for extraction of these types of files.

  • f : de-compress the file with extension .tar.gz or .tgz
  • x : extract files
  • t : to display the list of files available in the tgz archive
  • j : Unpack the files with .tbz2 or tar.bz2 extensions
  • z: Open the tar.gz or .tgz files

How to open or unpack tgz file in UNIX?

UNIX system works in a similar fashion as Linux. Let us see how we extract tgz files in the UNIX platform.

  1. Go to the command line window of UNIX.
  2. Enter the command as the text in yellow. Press ENTER.
$ gzip -dc logs.tgz | tar xf –
  1. Your file is extracted.

Now, another interesting step we can do here is, extract one file from the archive using the command line window.

In the above example, we will extract the PMGaugeEvent-15sep2020.log file from the logs.tgz archive.

  1. Enter the command as the text in yellow. Press ENTER.
tar -zxvf logs.tgz PMGaugeEvent-15sep2020.log
  1. You have successfully extracted the file from the tgz archive.

To view a list of all files in the tgz archive, please use the below command. Press ENTER.

tar -ztvf logs.tgz

Now, we will see other file extensions that can be opened / extracted / unpacked using the command line window.

  1. To extract the archive with .tar.gz extension, enter the below command. Press ENTER.
$ gzip -dc {filename}.tar.gz | tar xf –
  1. To extract the archive with .tar.Z extension, enter the below command. Press ENTER.
$ zcat {filename}.tar.Z | tar xf –
  1. To extract the archive with the tar.bz2 extension, enter the below command. Press ENTER.
tar -jxvf {filename}.tar.bz2 /documents/logs/server-ui

NOTE: In the above command, we have specified the destination folder where you want your archive file to be extracted. The destination folder is server-ui located under the logs folder.

You can use the below command to view the directory or folder in which your archive is extracted with all the files.

  1. Enter each command below and press ENTER.
ls -l
cd {destination folder name}
ls

How to open .tgz file in Windows using WinZip?

  1. Double-click the WinZip icon located on the desktop.
  2. Click the File menu, select the Open option.
  3. Go to the directory or folder where the tgz file is located.
  4. Select the file. The below pop up appears.
unpack tgz file
  1. Select the option to extract the files. See explanation of each option.
    • Yes, unzip the files to Desktop – All the files will be extracted and displayed on the desktop.
    • Yes, unzip the files to the Documents folder – All the files will be extracted in the Documents directory.
    • Yes, unzip the files to a folder I choose – All the files will be extracted in the folder selected by you
    • No, I don’t unzip the files – Files will not be extracted and the pop up will be closed.
  2. Select the Yes, unzip the files to a folder I choose option to select the folder location where you want to extract the files.
  3. Click the Unzip/Share tab from the top.
  4. The files will be extracted on the location you have chosen.

How to open .tgz file in Windows using 7-Zip?

You can also choose a 7-Zip tool, similar to WinZip to extract the tgz files in your Windows platform.

  1. Go to https://www.7-zip.org/ and download the exe file of 7-Zip tool.
  2. Complete the follow up instructions to install the tool.
  3. Once installed, create a desktop shortcut for 7-Zip.
  4. Double-click the desktop icon to open the 7-Zip window.
  5. Go to the File menu, click Open.
  6. Select the tgz file folder and click the Extract All button. The below dialog box will appear.
extract files
  1. Click 3 horizontal dots icon to select the destination folder in which you want to extract the files. 
  2. The file path will be shown in the Extract to: field.
  3. Click OK. All the files will be extracted in the folder you have selected.

How to open or unpack the .tgz file on Mac using Terminal?

  1. Open the terminal window. 
    • Press Command + SPACE keys.
    • Enter the keyword, Terminal.
    • The terminal window opens.
  2. Go to the folder where your tgz file is located using the cd command.
  3. Enter the below command. (In this, your tgz file name is logs.tgz). Press Return.
Tinasmacbook: ~ cd Desktop/
Users/Tinas/Desktop tar -x logs.tgz
  1. If the file is of a large size, you can see % progress of the extraction.
Tinasmacbook: ~ cd Desktop/
Users/Tinas/Desktop tar -xvf logs.tgz
  1. Once complete, you will see the extracted files on your desktop.

How to open or unpack the .tgz file on Mac?

  1. Open the finder window.
  2. Open the folder where your tgz file is located.
  3. Double-click the file. Your files will be extracted in the same folder.

Important Points in .tgz file

  • Not all tools support the archival and extraction of .tgz file formats. 
  • If you try to rename the file format, it will not change the file type. Avoid doing that.
  • To convert the file format, special software is required to do so. Search for the software for file conversion from one format to another.
  • There are chances of errors when you try to extract the tgz files with the tool that do not support extraction of this format.
  • Try to use .tgz format for taking backups and sharing logs from the server.
  • Always set a default path to which you want to save your extracted files. 
  • Try to use the command line window to extract the .tgz files.