Listing the Contents of a Zip File on Linux – Try Less!

You see a zip file. You want to see what’s in the zip file. What do you do? Well, there’s the fairly obvious:

unzip -l

list archive files (short format). The names, uncompressed file sizes and modification dates and times of the specified files are printed, along with totals for all files specified.

However, there’s another tool that can list the contents of a zip file. You’ll never guess: less!

~$ less 

Archive:   4476508 bytes   1168 files
drwxr-xr-x  3.0 unx        0 bx stor  1-Aug-13 13:49 wordpress/
-rw-r--r--  3.0 unx     9990 tx defX 21-Feb-13 14:24 wordpress/wp-settings.php
-rw-r--r--  3.0 unx     2718 tx defX 23-Sep-12 09:57 wordpress/wp-cron.php
-rw-r--r--  3.0 unx     3513 tx defX 16-Jul-13 07:19 wordpress/wp-comments-post.php
-rw-r--r--  3.0 unx     4616 tx defX 21-Jan-13 12:23 wordpress/wp-activate.php
drwxr-xr-x  3.0 unx        0 bx stor  1-Aug-13 13:49 wordpress/wp-admin/
-rw-r--r--  3.0 unx     2482 tx defX  8-Jan-12 10:01 wordpress/wp-admin/link-parse-opml.php
drwxr-xr-x  3.0 unx        0 bx stor  1-Aug-13 13:49 wordpress/wp-admin/js/
-rw-r--r--  3.0 unx     8489 tx defX 22-Mar-13 13:43 wordpress/wp-admin/js/editor.js
-rw-r--r--  3.0 unx     1575 tx defX 22-Aug-12 17:04 wordpress/wp-admin/js/user-profile.min.js
-rw-r--r--  3.0 unx      579 tx defX 22-Aug-12 17:04 wordpress/wp-admin/js/word-count.min.js

Virtually ever *nix install has less installed, so that’s quite handy if you ask me.


  1. zippy1981

    August 8, 2013 at 3:59 am

    On one hand this is cool to know. On the other hand, if less is getting this powerful, why not make it readonly vim at this point?

    Seriously, Bram should add an executable to vim that is called less that does everything that vim does, except edit buffers and write files. Give it a different status bar by default, and we should be good.


  2. larsks

    August 8, 2013 at 5:51 am

    You realize that less can’t actually read zip files, right? It’s using the LESSOPEN environment variable to identify an input preprocessor (on Fedora, it’s /usr/bin/ that ultimately ends up calling the “zipinfo” command. Because this requires several bits operating together to work, there’s a good chance that in some environments using less to view a zipfile simply won’t work.


  3. ThatGraemeGuy

    August 8, 2013 at 5:59 am

    Well damn! Upon further investigation it seems that “lesspipe” is doing the preprocessing, and supports a number of file types. See for example. This is by far the coolest “How did I not know this already?!?” tidbit I’ve learned in a long while.


  4. Twirrim

    August 8, 2013 at 8:41 am

    This is down to lesspipe, which allows data to be preprocessed before less gets to it.

    Which is really cool.

    Amongst some of the things you can do with it is less gzipd and bzipd files without uncompressing them as an explicit step 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

Follow TheNubbyAdmin!

follow us in feedly

Raw RSS Feed:

Contact Me!

Want to hire me as a consultant? Have a job you think I might be interested in? Drop me a line:

Contact Me!

Subscribe via Email

Your email address is handled by Google FeedBurner and never spammed!

The Nubby Archives

Circle Me on Google+!

Photos from Flickr

Me on StackExchange

The IT Crowd Strava Group