Linux Commands

How to View Contents of tar.gz File in Linux

Tar is a well-known Unix-based utility used to create tar files. Tar is a package for backup or a set of multiple files into one. Many files are stored in an uncompressed format and the archive’s metadata is in tar files.

Downloading distributions or projects of utilities containing .tar.gz can be easy but viewing the contacts of this file can be tricky. Many new or intermediate users face trouble viewing files in tar.gz. So, this guide has the explanation of methods to view the contents of the tar.gz file in Linux.

How to View Contents of tar.gz File in Linux

In this section, we will explain the ways to view the contents of tar.gz files using both CLI and GUI methods.

The CLI Method

For Linux, it is very easy to do any task through the command line. Here is the simple tar command to view the contents:

tar -zxvf file.tar.gz /home/<user>/<directory/ <filename>.tar.gz

Or

cd /home/<user>/<directory/ <filename>.tar.gz

tar -zxvf <filename>.tar.gz

For example, the sample.tar.gz file is located in the Downloads directory, we have to execute the following command in the terminal to view its content:

cd ~/Downloads

ls

tar -zxvf sample.tar.gz

With the tar command, you can use -t to view the contents of tar.gz files with the list of details. The -t switch is used to list the contents of the tar.gz file without actually extracting it.

tar -tvf sample.tar.gz

Here are the quick details about the tar command options:

Flags Description
-z Decompressing the resulting content with the GZIP command.
-x Extracting the contents of an archive to disk.
-v Showing the filename and progress while extracting files, (i.e., produces verbose output.)
-f Reading the archive from the specified file named data.tar.gz.
-t Listing out the content available in the archive file.

The GUI Method

In Ubuntu, there is a pre-installed application called Archive Manager to handle archive files (.zip or .tar files). This tool lets you graphically extract, view, and change the archive files.

Viewing content from tar.gz files through the GUI method is ‌ more accessible than the command-line method. Go to the folder where your tar.gz file is located.

Right-click on the file and there will be an Open With Archive Manager option.

Once you click on this option, the system will open a new window by which you can access and view the contents of the tar.gz file.

Conclusion

In the above information, we have all the information to view the contents of tar.gz files in Linux. We have thoroughly explained both the CLI and GUI methods. Many Linux users prefer GUI rather than CLI because it is much easier to use. After running a command through the CLI method, you get the complete list of contents and the details in one place as output. However, the result of both approaches will be the same.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.