In my bash command line, when I use unzip -l test.zip I get the output like this:

Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
   810000  05-07-2014 15:09   file1.txt
   810000  05-07-2014 15:09   file2.txt
   810000  05-07-2014 15:09   file3.txt
---------                     -------
  2430000                     3 files

But I am interested only by the lines containing the file details.

I tried to make filtering using grep like this:

unzip -l test.zip | grep -v Length | grep -v "\-\-\-\-" | g -v Archive | grep -v " files"

But it is long and prone to error (e.g a file name Archive in this list will be dropped)

Is there any other options with unzip -l (I checked the unzip man page and did not find any) or another tool to do so?

It is important to me to not really unzip the archive but just to look what files are inside.

  • The accepted answer is much better than this; but I want to remark that anything with multiple grep can be refactored into an Awk script, usually with much improved precision. awk 'NR >3 { if (/^ *---/) exit 0; print }' would trim the first three lines as well as the footer, and also be within reach of easily extracting just the file name (hint: print substr($0, 29)). – tripleee Nov 22 '17 at 11:16
  • Yes, I totally agree, that's is exactly why I ask that specific question: to have a better and viable solution. – рüффп Dec 20 '17 at 22:08
zipinfo -1 file.zip


unzip -Z1 file.zip

Would list only the files.

If you still want the extra info for each file names, you could do:

unzip -Zl file.zip | sed '1,2d;$d'


unzip -l file.zip | sed '1,3d;$d' | sed '$d'

Or (assuming GNU head):

unzip -l file.zip | tail -n +4 | head -n -2

Or you could use libarchive's bsdtar:

$ bsdtar tf test.zip

$ bsdtar tvf test.zip
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file1.txt
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file2.txt
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file3.txt

$ bsdtar tvvf test.zip
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file1.txt
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file2.txt
-rw-rw-r--  0 1000   1000   810000 Jul  5  2014 file3.txt
Archive Format: ZIP 2.0 (deflation),  Compression: none
  • thanks powerful sed... exactly what I wanted; Also the zipinfo tool is interesting, I didn't know it. – рüффп May 7 '14 at 14:59
  • Is there a way to ignore directories? unzip -Z1 zipfile.zip will output: directory/ and directory/file.extension (Note: directory names with . is likely, so adding a | grep . doesn't work) – Matt Nov 26 '19 at 22:54
  • I was also looking for a way to exclude directories from the listing (bsdtar -tf also prints directories just like unzip -Z1), afaik this may be the only option: unzip -Z1 test.zip | grep -v '/$', since all entries that are just directory names have a trailing slash ( /). nb: however, if the goal was to remove directory prefix from the path, then each line would have to be processed with basename or bash equivalent stackoverflow.com/questions/965053/… – michael May 29 '20 at 4:06

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.