Search code examples
tarunzip

Listing the contents of zip files within a tar file


I've got a tar file. Inside of it are a number of zip (not gzip) files. I want to list the contents of the zip files without extracting anything.

I can do tar tf to list the files then iterate through them and do unzip -l on each of the zip files.

Is there an elegant (one-line) way to do this?


Solution

  • Starting with tar, you can get it to write to stdout with the -O command line option.

    Next to the unzip part of the problem. The standard Linux infozip versions of zip/unzip don't support reading input from stdin. The funzip command, which is part of infozip can read from stdin, reads from stdin but it only supports uncompression. It doesn't have an option to list the contents.

    Luckily Java jar files are really just zip files with a well-defined structure and the jar command can read from stdin and list the contents of the input file

    So, assuming you have a tar file called my.tar that only contains zip files, something like this should list the names of the files in the embedded zip files

    tar xOf my.tar | jar -t