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?


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

  • Is this : symbol used to refer to zip file relationship only, or have other usages? – Zen Aug 18 '14 at 2: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 2: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 2:59
  • 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 8:44
  • 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 0:41

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).


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.

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.