View list of files in ZIP archive on Linux

433

57

How can I view the list of files in a ZIP archive without decompressing it?

danidacar

Posted 2010-11-30T09:05:54.060

Reputation: 4 783

Is it possible to do the same for a regular unix archive? (tar/gzip/bz2/ etc) – ThorSummoner – 2014-10-17T16:59:55.657

tar tvf. if .gz, add a z. For bz2, add j. Lots more, check the man page. – UtahJarhead – 2015-10-19T20:22:44.800

Answers

494

The less utility is capable of peeking into a zip archive. In fact, if you look at the outputs of unzip -l zipfile and less zipfile, you will find them to be identical.

ayaz

Posted 2010-11-30T09:05:54.060

Reputation: 8 106

10@ayaz In what system does less list zipfiles? I see comments telling that it does not work on MAC, Ubuntu, and here I use Debian. Debian also shows binary garbage. – Dr Beco – 2014-08-12T04:38:33.840

13In Ubuntu, try view [zipfile]. – Samuel Lampa – 2014-09-10T16:07:58.727

4WRONG. unzip -l works well to show the files inside of a zip archive, but less gives out binary content in many cases and that's a mess of course. – Arturas M – 2014-11-05T13:48:01.427

18You need the lesspipe helper installed to enable zip file support for less. It's standard on many linux systems but not on OSX, but you can install it with brew. – pimlottc – 2015-06-18T19:37:59.723

6It's a neat hack to use less, but unzip -l seems like the canonical answer, esp. given that it's a far more universal answer. – Mark E. Haase – 2015-06-29T21:30:23.883

zipinfo myFile.zip produces more info and particularly it lists UNIX file permissions whereas unzip -l is less verbose. My comment is based on zipinfo 3.0 and unzip 6.0 dated from April 2009. – Svilen – 2016-01-27T12:51:08.347

FYI: .jar files (java archive) are zip files. – Christian Bongiorno – 2017-10-11T21:52:20.687

view [zipfile] also works in Debian 10 – Webwoman – 2019-12-16T15:38:14.933

110Note, that less zipfile on MacOS-X displays the binary filecontent, so you see a lot of garbage instead of the content of the zip-file. Then you should opt for the ``ùnzip -l zipfile``` – heiglandreas – 2013-01-25T09:59:53.293

I get slightly more information from unzip compared to less. Just saying. – matt burns – 2013-05-07T10:57:21.247

123

Try unzip -l files.zip | less

Also, See man unzip for more options

Ken Ratanachai S.

Posted 2010-11-30T09:05:54.060

Reputation: 1 532

7You can skip the pipe to less command. It is great idea in a big collection of files, though. – omar – 2014-07-09T14:39:08.633

70

To list zip contents:

zipinfo -1 myzipfile.zip

For detailed output:

zipinfo myzipfile.zip

kinORnirvana

Posted 2010-11-30T09:05:54.060

Reputation: 811

7Nice answer, you don't have to parse the output just to get filenames. – Antoine Pelisse – 2014-10-31T23:04:34.570

Is that supposed to be a 1 and not an l? – Mathias Lykkegaard Lorenzen – 2020-01-03T13:33:20.250

41

Please use

vim ZIP_FILE_NAME

for the same. This is a simple and easy to remember one.

Rajasekhar Tolety

Posted 2010-11-30T09:05:54.060

Reputation: 435

5Nice, this also allows to open individual files in the archive without doing the unzip – user3885927 – 2016-09-22T17:25:26.263

Quite unexpected, and extremely handy! Thanks! – Pierre – 2019-02-01T16:46:53.283

Actually: this wont work if unzip is not installed on the system. Besides that, awesome! – sjas – 2019-03-24T22:04:57.687

15

You can make the zip appear as a directory (in which you use cd, ls, etc.) by mounting it with the fuse-zip virtual filesystem.

mkdir foo.d
fuse-zip foo.zip foo.d
ls foo.d
cat foo.d/README
...
fusermount -u foo.d
rmdir foo.d

Another relevant FUSE filesystem is AVFS. It creates a view of your entire directory hierarchy where all archives have an associated directory (same name with # tacked on at the end) that appears to hold the archive content.

mountavfs
ls ~/.avfs/$PWD/foo.zip\#
cat ~/.avfs/$PWD/foo.zip\#/README
...
umountavfs

Many modern file managers (e.g. Nautilus, Dolphin) show archive contents transparently.

AVFS is read-only. Fuse-zip is read-write, but beware that changes are only written to the zip file at unmount time, so don't start reading the archive expecting it to be modified until fusermount -u returns.

Gilles 'SO- stop being evil'

Posted 2010-11-30T09:05:54.060

Reputation: 58 319

Nice, Giles. Thanks. Just a quick: can one add files to it by justing "cp"ing to the directory? – Dr Beco – 2014-08-12T04:45:35.433

@DrBeco With fuse-zip, yes. With avfs, no. – Gilles 'SO- stop being evil' – 2014-08-12T09:15:16.487

10

At least in Ubuntu, the possibly easiest command is:

view [zipfile]

This will open up the file listing in your standard text editor (nano, vim etc).

Samuel Lampa

Posted 2010-11-30T09:05:54.060

Reputation: 525

2

If you're more graphically oriented, Midnight Commander can also browse zip files as if they were regular directories.

Charles Burge

Posted 2010-11-30T09:05:54.060

Reputation: 1 792

2

A more comprehensive solution: vim || emacs

The previous answer by @kinORnirvana is my favorite to produce a file with the content of a zip archive.

zipinfo [-1] archive.zip > archive_content.txt

However, I recommend vim or emacs (not nano) if you need to browse into an archive file or even to view the content of a file contained inside it.

vim archive.zip

This approach works with other archive formats too:

vim file.tar
vim file.tar.gz
vim file.tar.bz2

With vim or emacs you can:

  • browse the directory structure of the archive file.
  • view the content of any file inside the archive file.

enter image description here

ePi272314

Posted 2010-11-30T09:05:54.060

Reputation: 221

2

Its actually unzip -l file.zip | grep "search" or if you have a lot of files

for i in `ls *zip`; do 
  unzip -l $i | grep "search"; 
done

Update: Changed from '-p' to '-l' in order to search for files.

Rob

Posted 2010-11-30T09:05:54.060

Reputation: 21

1

(yaa) Yet another answer:

Alias this command:

alias vless='/usr/share/vim/vim73/macros/less.sh'

and you can use vless file.zip to take advantage of vi (or vim) less script.

(also good to substitute less, so you can have colors)

Dr Beco

Posted 2010-11-30T09:05:54.060

Reputation: 1 277

1less -R do support ANSI colors. – Sylvain Leroux – 2016-11-18T14:19:04.270

0

Try this -

zipdetails yourFileName.zip

URL87

Posted 2010-11-30T09:05:54.060

Reputation: 297

2Could you possibly include some example outputs? Is zipdetails part of the standard Linux kernel or would the OP need to install this separately? – Burgi – 2020-02-10T15:46:42.317

Wouldn't it be better to use zipdetails yourFileName.zip | grep "Filename "? – zx485 – 2020-02-10T23:24:45.273