Linux Commands

How to view contents of ZIP archive in Linux

You most probably have used compression and archiving techniques for backup or for saving space on your hard disk. To view and access the contents of those archives, you have to extract them in a directory, which seems a pretty easy task. However, if you are dealing with the archive containing a large number of files or the files with big size, then it will become a time-consuming and annoying task. There are some commands in Linux that allows you to quickly view the contents of an archive without extracting it.

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:

$ zmore <archive_name>

or

$ zless <archive_name>

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:

$ zcat <archive_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:

$ vim <archive_name>

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:

$ sudo ap-get install zip unzip

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:

$ zip –sf <archive_name>

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:

$ unzip –l <archive_name>

To view the contents of all the files, use unzip with -c flag as follows:

$ unzip –c <archive_name>

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:

$ unzip –c < archive_name> filename

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:

$ sudo apt install p7zip-full

Once installed, you can view the contents of a ZIP archive using the l flag as follows:

$ 7z l <archive_name>

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.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.