Categories: LinuxLinux Command

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:

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.

fosstechi

Recent Posts

How to List or Display all Cron Jobs in Linux

Cron is a command-line job scheduler available on Linux operating systems that allows users to…

1 year ago

How to Disable IPv6 on RHEL System

In computing, there are two types of IP addresses, IPv4 and IPv6. By default, IPv6…

1 year ago

How to Create tar.gz File in Linux

A tar archive is a file that stores a collection of directories and files, also…

2 years ago

How to Identify LUN Mapped to VxVM Disk in Linux

On Linux, you can quickly find out how LUNs are mapped to the underlying OS…

2 years ago

How to List Available Package Updates in Ubuntu

Keeping your Ubuntu system up-to-date is critical to ensuring a system's stability and security. This…

2 years ago

How to Check if Your Linux System Uses UEFI or BIOS

When you boot a Linux system, it boots into legacy BIOS (Basic Input/Output System) mode…

2 years ago

This website uses cookies.