Sol
Sol

Reputation: 1005

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?

Upvotes: 2

Views: 1015

Answers (2)

mxmlnkn
mxmlnkn

Reputation: 2141

You can use ratarmount to mount the archive. This gives you a folder view without extracting anything. And moreover, it can recursively mount archives inside archives inside archives to almost arbitrary depth.

pip install --user ratarmount
ratarmount --recursive tar-with-zips.tar mountpoint
find mountpoint/

Upvotes: 1

pmqs
pmqs

Reputation: 3705

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

Upvotes: 1

Related Questions