How can I view the list of files in a ZIP archive without decompressing it?
12 Answers
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.
-
177Note, 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``` Jan 25, 2013 at 9:59 -
23@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.– DrBecoAug 12, 2014 at 4:38
-
24
-
32You 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.– pimlottcJun 18, 2015 at 19:37 -
24It's a neat hack to use
less
, butunzip -l
seems like the canonical answer, esp. given that it's a far more universal answer. Jun 29, 2015 at 21:30
Try unzip -l files.zip
Or unzip -l files.zip | less
if there are too many files to be listed in one page.
Also, See man unzip
for more options
-
12You can skip the pipe to
less
command. It is great idea in a big collection of files, though.– omarJul 9, 2014 at 14:39 -
You can also add
-v
argument to include verbose details about compression for each file. Mar 6, 2022 at 14:26
To list zip contents:
zipinfo -1 myzipfile.zip
For detailed output:
zipinfo myzipfile.zip
-
11Nice answer, you don't have to parse the output just to get filenames. Oct 31, 2014 at 23:04
-
1
-
1@MathiasLykkegaardLorenzen according to
man zipinfo
:-1 list filenames only, one per line. This option excludes all others; headers, trailers and zipfile comments are never printed. It is intended for use in Unix shell scripts.
Jul 15, 2020 at 23:16 -
The
-1
flag matches thels
command.ls -1
prints all files, one line per file. Aug 19, 2020 at 21:16
Please use
vim ZIP_FILE_NAME
for the same. This is a simple and easy to remember one.
-
9Nice, this also allows to open individual files in the archive without doing the unzip Sep 22, 2016 at 17:25
-
-
Actually: this wont work if
unzip
is not installed on the system. Besides that, awesome!– sjasMar 24, 2019 at 22:04
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.
-
Nice, Giles. Thanks. Just a quick: can one add files to it by justing "cp"ing to the directory?– DrBecoAug 12, 2014 at 4:45
-
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).
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.
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.
If you're more graphically oriented, Midnight Commander can also browse zip files as if they were regular directories.
(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)
-
1
it is possible to peek inside also with zmore
, zless
, zcat
, but with vim
is in a structured way
Try this -
zipdetails yourFileName.zip
-
2Could you possibly include some example outputs? Is zipdetails part of the standard Linux kernel or would the OP need to install this separately?– BurgiFeb 10, 2020 at 15:46
-
1Wouldn't it be better to use
zipdetails yourFileName.zip | grep "Filename "
?– zx485Feb 10, 2020 at 23:24 -
1
Zipdetails displays information about the internal record structure of zip files. It is not concerned with displaying any details of the compressed data stored in the zip file.
zipinfo seems much more appropriate here– xerufOct 15, 2021 at 10:27 -
@zx485 Using Redhat 7, I'm unable to use any commands in other answers, and we're unable to request to install anything on that server. Your solution was useful, thanks! Aug 3, 2022 at 0:09