May 12, 2024

How to View Contents of tar.gz File in Linux

A tarball is commonly known as a TAR file, short for tape archive, which is an archive file type commonly used in Linux and Unix operating systems to create and compress archives.

Compressing files and directories is a great way to save a good amount of disk space on a Linux system when the disk space limit is reached. On the other hand, you can delete unused nor old files that are no longer needed.

The tar command comes with various functions which we have already discussed in different aspects. But in this guide, we will discuss a lesser-known feature of tar that displays the contents of a tar.gz file without extracting it.

Syntax of tar Command

The below general syntax of the tar command can be used to view the contents of a tar files such as tar, tar.gz, tar.bz2, and tar.xz.

Syntax:
tar -tvf [Archive_File_Name]
Flag/InfoDetails
tarLinux Command
-tTo list the contents of an archive
-vIt shows more detailed information about the files/directories in the archive (display all information).
-fThis specifies the archive file name you want to view.
Archive_File_NameSpecifies the archived file which user wants to visualize.

1) Viewing the Contents of a tar.gz File

To view the contents of a 'tar.gz' file without extracting it, run: This will show file and directory name along with other information’s such as file permission, owner & group information, files/directories size, and date & timestamp.

tar -tvf FossTechi.tar.gz
or
tar -tzvf FossTechi.tar.gz

Output:

Viewing the Contents of a tar.gz File in Linux

1.1) Viewing only the file Names

To view only the name of the files in the tar.gz archive file, simply run:

tar -tf FossTechi.tar.gz
or
tar -tzf FossTechi.tar.gz

home/linuxgeek/shell-scripts/
home/linuxgeek/shell-scripts/asm_disk_mapping_1.sh
home/linuxgeek/shell-scripts/asm_disk_mapping.sh
home/linuxgeek/shell-scripts/kill-user-sessions.sh
home/linuxgeek/shell-scripts/block_device_mapping_with_LUN_FS.sh
home/linuxgeek/shell-scripts/block_device_mapping_with_LUN.sh

2) Reading the Contents of a tar File

To view the contents of a '.tar' file without extracting it, run:

tar -tvf FossTechi.tar

3) Listing the Contents of a tar.bz2 File

To view the contents of a 'tar.bz2' file without extracting it, run:

tar -tvf FossTechi.tar.bz2
or
tar -tjvf FossTechi.tar.bz2

4) Displaying the Contents of a tar.xz File

To view the contents of a 'tar.xz' file without extracting it, run:

tar -tvf FossTechi.tar.xz
or
tar -tjvf FossTechi.tar.xz

Wrapping up

In this article we have explained the method to visualize the content of tar, tar.gz, tar.bz2, and tar.xz files without extracting them using the ‘-t’ option (list table of contents), along with various examples.

Leave a Reply

%d bloggers like this: