10

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/
...
  • In the question title, your usage of the word enlist is wrong. You might want to use list instead. – Jonathan Ginsburg Apr 22 at 20:30
  • @JonathanGinsburg thanks – Sapir Aug 27 at 15:02
10

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 "/."
| improve this answer | |
  • @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 6 '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 7 '17 at 22:40
4

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>}$"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.