Please assign a menu to the primary menu location under menu


How to View the Contents of ZIP or TAR Files Without Extracting in Linux

Bash Shell

Working with archives is a common task in Linux, but sometimes, you may not know what the contents of the archive look like. If you want to take a peek at the inside of a ZIP or TAR file without extracting it, there are tools that can help you.

Using unzip to View ZIP Files

To view inside ZIP files, you’ll need the unzip utility, which might not be included by default. You can install it from your system’s package manager if it isn’t:

sudo apt install zip unzip

This utility is used to extract ZIP files, but with the lowercase -l flag, it will list the contents instead:

unzip -l file

If you want just a raw list of all the files in the archive, you can use zipinfo with the -1 flag to only print filenames:

zipinfo -1 file

This can be useful for bash scripts, or when piped to other commands like less, which can help you search through a large archive. You can also pipe it to a text utility like grep or sed to find matches for certain files:

zipinfo -1 file | grep string

RELATED: How to Use the less Command on Linux

Using tar to View tarballs

TAR archives, also known as tarballs, are another kind of archive format used commonly in Linux. You can also print the contents of these without extracting them, by using the -t flag

tar -tf filename.tar.gz

Like zipinfo, this prints a raw list of all the files, and can be piped to other utilities for processing.


Leave a Reply

This website uses cookies. By continuing to use this site, you accept our use of cookies.