In this article, we will see some of the Linux commands that will help us to view the contents of an archive without the need to extract them.
Please note that we have explained the procedure and commands described in this article on a Debian 10 system.
Viewing the contents of ZIP archive
Using zmore and zless
Similar to more and less command in Linux, these commands can be used to view the contents of a file from the command line without extracting. Zmore and Zless command works perfectly for a ZIP file; however, these do not work for a ZIP folder that contains the multiple files.
To view the contents of a ZIP file without extracting, simply use zmore or zless command followed by the filename:
or
Using zcat
Similar to zmore and zless commands, zcat can also be used to view the contents of a ZIP archive without extracting it. To view a compressed file, use zcat followed by the file name:
It also does not work with ZIP folders containing multiple files. If you run zcat to view a ZIP archive that contains the multiple files, it will only show one file ignoring the rest of the files, as shown in the following screenshot.
Using Vim
Vim command can also be used to view the contents of a ZIP archive without extracting it. It can work for both the archived files and folders. Along with ZIP, it can work with other extensions as well, such as tar.xz, tar.bz2, tar, tbz.
To view a compressed file, use zcat followed by the filename:
It allows us to browse through the list of files in an archived folder and view the contents of a specific file as well. In order to view a specific file, use the arrow and Enter keys to select the file and press Enter or use the left click to open the specific file.
In order to view a specific file, select it using the arrow keys and then hit Enter
Using zip and unzip command
Zip is the most common method of archiving the files, while the unzip helps to extract those files. When unzip command is used without any flag; it extracts all the files contained in a ZIP archive. However, we can use it to view the contents of a file without extracting it by using a specific flag. Similarly, the zip command can also be used to view the list of files in an archive without decompressing it. However, it cannot be used for viewing the contents of a file.
To use zip and unzip, you will first need to install them in your system. To do so, execute this command in Terminal:
In order to use the zip command for browsing the list of files inside a ZIP archive without decompressing, type zip followed by –sf and the archive name as follows:
The unzip command allows you to view the contents of a file along with browsing the list of files. It works for both the ZIP archived files and folders.
To browse the list of files in an archived folder, use unzip with –l flag as follows:
To view the contents of all the files, use unzip with -c flag as follows:
In order to view the contents of a specific file in the archive folder, add the filename at the end of the above command as follows:
Using 7z
7z is another useful tool used for archiving and extracting the files. It supports various extensions, including ZIP, 7Z, XZ, TAR, WIM, etc. It can also be used for viewing the list of files in an archive without extracting them. However, it does not support displaying the contents of files in an un-extracted format.
To install the 7z utility, execute this command in Terminal:
Once installed, you can view the contents of a ZIP archive using the l flag as follows:
In this article, we have discussed some Linux commands for viewing the contents of an archive file. By using these commands, you will no longer need to extract the heavy archive files for just viewing their content.