Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of directories in a zip?

I am looking for a way to list the directories in a zip file in bash under Linux. I found out there is an application called zipinfo, which can list the paths in the zip (without any extra noise to have to parse through (zipinfo -1 foo.zip), as opposed to unzip -l foo.zip). However, this isn't good enough and I am wondering if there is a better way.

like image 694
carlspring Avatar asked Sep 10 '15 17:09

carlspring


1 Answers

To list only directories:

unzip -l foo.zip "*/"

Output (e.g.):

Archive:  foo.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2015-09-10 20:10   work/
        0  2015-08-31 10:45   work/test1/
        0  2015-08-31 10:50   work/test1/cc/
        0  2015-08-31 10:45   work/test1/dd/
        0  2015-08-31 10:45   work/test1/aa/
        0  2015-08-31 10:45   work/test1/bb/
        0  2015-09-09 21:17   work/tmp/
        0  2015-08-23 18:49   work/tmp/work/
        0  2015-09-08 19:33   work/tmp/work/loop/
        0  2015-08-15 16:00   work/tmp/work/1/
        0  2015-08-15 16:00   work/1/
        0  2015-08-24 18:40   work/dir/
        0  2015-09-05 18:07   work/rename/
---------                     -------
        0                     13 files

or use

zipinfo -1 foo.zip "*/"

Output (e.g.):

work/
work/test1/
work/test1/cc/
work/test1/dd/
work/test1/aa/
work/test1/bb/
work/tmp/
work/tmp/work/
work/tmp/work/loop/
work/tmp/work/1/
work/1/
work/dir/
work/rename/
like image 166
Cyrus Avatar answered Oct 25 '22 11:10

Cyrus