11

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/
...
Sapir
  • 113
  • 1
  • 6

2 Answers2

11

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 "/."
dvb
  • 435
  • 4
  • 7
  • @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 Dec 06 '17 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 – dvb Dec 07 '17 at 22:40
  • Piping to `grep -v "/."` works also with the output of `zip -sf` or `unzip -l` – Paloha Sep 03 '21 at 11:21
5

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>}$"