17

I have a big zip file and I want to know what it's contain. I know I can run:

zipinfo file.zip

but the output is too verbose and there are a lot of files in the sub-directories.

I want to see a list of the files in the top level.

Example

If the normal output is:

-sh-3.2$ zipinfo file.zip
Archive:  file.zip   999999999 bytes   99999 files
-rw-r--r--  2.3 unx     3894 tx defN  3-Jul-11 13:11 file1
drwxr-xr-x  2.3 unx        0 bx stor 23-Feb-12 21:00 dir1/
-rw-r--r--  2.3 unx      269 tx defN 23-Oct-11 14:34 dir1/file2
drwxr-xr-x  2.3 unx        0 bx stor 25-Sep-11 03:53 dir1/subdir1/
...
drwxr-xr-x  2.3 unx        0 bx stor 23-Feb-12 21:00 dir2/
...

I want a command that will output:

-sh-3.2$  <answer>
Archive:  file.zip   999999999 bytes   99999 files
-rw-r--r--  2.3 unx     3894 tx defN  3-Jul-11 13:11 file1
drwxr-xr-x  2.3 unx        0 bx stor 23-Feb-12 21:00 dir1/
drwxr-xr-x  2.3 unx        0 bx stor 23-Feb-12 21:00 dir2/
drwxr-xr-x  2.3 unx        0 bx stor 23-Feb-12 21:00 dir3/
...
2
  • In the question title, your usage of the word enlist is wrong. You might want to use list instead. Commented Apr 22, 2020 at 20:30
  • @JonathanGinsburg thanks
    – Sapir
    Commented Aug 27, 2020 at 15:02

2 Answers 2

15

You can filter the output with grep. Here I'm telling grep to hide all rows that contain a slash '/' and anything after the slash:

zipinfo file.zip | grep -v "/."
4
  • @dvb - many thanks ...any way to display size of dirs ? it shows 0 for 'length' column for many dirs which I know have content.
    – killjoy
    Commented Dec 6, 2017 at 15:53
  • @killjoy this worth a separate question. you might first get a list of all files and folders with their size recursively, and then use grep to get only the first level Commented Dec 7, 2017 at 22:40
  • Piping to grep -v "/." works also with the output of zip -sf or unzip -l
    – Paloha
    Commented Sep 3, 2021 at 11:21
  • This "/." seemed confusing at first, I was thinking "surely he meant ./, but why would that work?". But no, it's very smart ! The pattern works by selecting everything that is not a directory, as the slash is followed by "something" (.), and then inverting that, so we only get directories Commented Jan 3, 2023 at 16:19
6

Expanding and building on top of @dvb's answer, you can set the deepness level with extended regular expressions:

zipinfo file.zip | egrep "^([^/]*/?){<deepness-level>}$"
1
  • Note: this only work for ASCII file/dir names
    – vladkha
    Commented Jan 17 at 23:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .