How to get a list of directories in a zip file?

I am looking for a way to list directories in a zip file in bash under Linux. I found out that there is an application called zipinfothat can list the paths in zip (without too much noise to do parsing ( zipinfo -1 foo.zip), not unzip -l foo.zip). However, this is not good enough, and I wonder if there is a better way.

+4
source share
2 answers

To list directories only:

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

zipinfo -1 foo.zip "*/"

(,):

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/
+5

unzip -l awk :

unzip -l foo.zip | awk '/\/$/ { print $NF }'

unzip -l $NF .

0

Source: https://habr.com/ru/post/1606835/


All Articles