linux - Recursively listing the contents of a tar/zip archive -


i understand how contents of zip/tar files, example: http://www.if-not-true-then-false.com/2010/list-tar-tar-gz-tar-bz2-contents/

but in case: want contents of zip archive.

abcd.zip   -->somefile.txt   -->somezip.zip   -->someother.tar 

objective: want contents of abcd.zip further inside somezip.zip , someother.tar, , someother.tar may have other zips etc. how can recursion? possibly bash/perl script?

here perl script list files including recursion on zip , tar files:

#!/usr/bin/env perl  use strict; use warnings; use archive::extract; use file::temp;  ($indent) = (0);  die qq|usage: perl $0 <zip-file>\n| unless @argv == 1;  printf qq|%s\n|, $argv[0]; $indent += 2; recursive_extract( shift );  exit 0;  sub recursive_extract {         ($file) = @_;          $tmpdir = file::temp->newdir;          $ae = archive::extract->new(                 archive => $file,         );            $ae->extract( => $tmpdir->dirname );          $f ( @{ $ae->files } ) {                  printf qq|%s%s\n|, q| | x $indent, $f;                  if ( $f =~ m/\.(?:zip|tar)\z/ ) {                          $indent += 2;                         recursive_extract( $f );                 }            }             $indent -= 2; } 

some drawbacks: doesn't cache processed files, if there identical compressed files, extract , read them again. , search compressed files looking in extension, not content. can improved need or want it.

assuming following script named script.pl, give zip file argument, running like:

perl script.pl myzip.zip 

and in test yields like:

myzip.zip   f1   f2   f3   f4   mytar.tar     f5     f6     f7     f8     testtar.tar       f11       f12       f13       f14   testtar.tar     f11     f12     f13     f14   testzip.zip     fd     fd2 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -