Tar is a prominent Linux utility and comes with various functions such as creating archives, extracting them, extracting them to a specific directory, adding more files to the existing archive, etc. But can I view the content of the Tar file specifically while using the terminal? The answer is Yes! This multi-feature utility also allows viewing the content of the archived files, especially when working on the server and no graphical tool is available. Viewing the tar file content can also be quite handy when the file is quite large, and you only want to find a specific and extract it.
We have already discussed many features of the Tar utility. This guide focuses on a lesser-known feature of Tar utility and displays or listing the content of the tar file. So, let’s begin:
How to view the content of a tar file
You need to view the content of a tar file as it collects many files and ensures if a specific file is present. The syntax of the command to view the content of a tar file without extracting it is mentioned below:
- “-t”/ “–list”: Used to list the content of the tar file
- “-f”/ “–file”: Commanding the utility to use the file mentioned in the following argument
Moreover, you can use the “-v” flag or “–verbose” option to get detailed standard output. Let’s understand it by an example:
With verbose flag:
The long command would be:
In the above command, I am viewing the content of a “my_doc_file.tar” file.
How to view the content of tar.gz or tgz files
As it is known that a tar file does not compress the files, it simply collects. To compress it, we need another utility. A commonly used utility to compress tar files is “gzip.” The command to view the content of a “tar.gz” or “tgz” file is mentioned below:
The long command would be:
Where “-z” and “–gzip” options are used to handle the “tgz” or “tar.gz” files.
How to view the content of tar.bz, tar.bz2,tbz, or tbz2 files
The “tzip” is another utility for the compression of tar files. To view the content of files with extension “tar.bz”, “tar.bz2”, “tbz” or “tbz2”, follow the below-mentioned command:
And the long command would be:
The “-j” flag is used to handle “bzip” files.
How to view the content of tar.xz files
The “tar.xz” files are the tar files that are compressed using the “LZMA/LZMA2” algorithm. To view the content of files with “tar.xz” files, use:
The “-J” and “–xz” options are used to handle “tar.xz” files.
Tar is a feature-rich Linux utility that allows viewing the content of various tar archive files without extracting it. Regarding the content of a tar file in the terminal can be helpful in many situations. In this guide, we explore how to view the content of tar files and compressed tar files in the terminal using different flags and long commands. To get more about Tar utility, run “man tar” in the terminal.