5

I know I can use unzip -l file.zip to view the file list of a zip file.

But a got a zip file inside another zip file. I tried unzip -l file.zip/sub_file.zip, but failed.

Is it possible to view the file list of the sub_file.zip without extract it out?

Zen
  • 7,537

3 Answers3

2

You can use less with Wolfgang Friebel's lesspipe script: less file.zip:sub_file.zip

vinc17
  • 12,174
  • Is this : symbol used to refer to zip file relationship only, or have other usages? – Zen Aug 18 '14 at 02:56
  • I got this: zipinfo: cannot find or open 2014-08-16.zip:info_2014-08-16.zip, 2014-08-16.zip:info_2014-08-16.zip.zip or 2014-08-16.zip:info_2014-08-16.zip.ZIP – Zen Aug 18 '14 at 02:58
  • But I have this info_2014-08-16.zip file in the 2014-08-16.zip file. `[admin@cjxx-s1 platform]$ unzip -l 2014-08-16.zip Archive: 2014-08-16.zip Length Date Time Name

    3145521 08-17-2014 00:47 info_2014-08-16.zip 1047822 08-17-2014 00:47 pay_2014-08-16.zip 46524282 08-17-2014 00:48 spend_2014-08-16.zip`

    – Zen Aug 18 '14 at 02:59
  • @Zen : is used to accede files in archives supported by lesspipe, recursively. If you get such errors, it seems that you are not using Wolfgang Friebel's lesspipe. – vinc17 Aug 18 '14 at 02:59
  • got it, it means I need to install a lesspipe program first, right? But that's not a good universal solution, I think. – Zen Aug 18 '14 at 03:03
  • @Zen lesspipe is so useful that it should be universal. I can't live without it: used with less (for which it has been written), it's the universal viewer in a text terminal. – vinc17 Aug 18 '14 at 03:06
  • I'm confused, less is an inside build program on Ubuntu, I can use it without installing anything, but is this less command the same thing with lesspipe? If they are the same thing, why my less file.zip:sub_file.zip doesn't work? – Zen Aug 18 '14 at 03:21
  • 2
    @Zen This is the same less: lesspipe is an input preprocessor, used with the LESSOPEN environment variable, e.g. export LESSOPEN="|/path/to/lesspipe %s". See the less(1) man page for more information. – vinc17 Aug 18 '14 at 08:44
  • I was in the middle of writing an answer here, but... does this work recursively? I guess it just creates as many temp files as it needs? I like this - I have lesspipe but I am not sure about Wolfgang... I need to check. In the meantime, screw my answer. – mikeserv Aug 19 '14 at 00:28
  • 1
    @mikeserv The README file says that file extraction works up to a depth of 6. I suppose that this is sufficient in practice! Note that this also works with compressed files (.gz, etc.), with .deb files, and so on. Internally temp files (or pipes) are used, but this is transparent. If the lesspipe script doesn't contain the text "Wolfgang Friebel", you don't have the right one. – vinc17 Aug 19 '14 at 00:41
2

unzip -l file.zip/sub_file.zip doesn't work because file.zip isn't a directory: it's a regular file that happens to be in an archive format. But you can create a directory that mirrors the content of the zip file, by mounting a filesystem that presents a view of the content of the zip file. There are several choices, pick whichever is easiest to install on your distribution:

For example, with archivemount:

mkdir file.d
archivemount file.zip file.d
unzip -l file.d/sub_file.zip
fusermount -u file.d

or even

mkdir file.d sub_file.d
archivemount file.zip file.d
archivemount file.d/sub_file.zip sub_file.d
ls -lR sub_file.d
fusermount -u sub_file.d
fusermount -u file.d

See Extract only a specific file from a zipped archive to a given directory, How do I recursively grep through compressed archives? and Search for files with a specific size inside recursive zipped archives for examples of AVFS and fuse-zip in similar situations.

1

With zsh:

$ unzip -l a.zip.zip
Archive:  a.zip.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      195  2014-08-18 09:38   a.zip
---------                     -------
      195                     1 file

$ unzip -l =(unzip -p a.zip.zip a.zip)
Archive:  /tmp/zsh0i0JyZ
  Length      Date    Time    Name
---------  ---------- -----   ----
       55  2014-08-15 15:24   a
---------                     -------
       55                     1 file

=(...) is a third form of process substitution that uses a temporary file instead of a pipe (unzip only works with seekable files).