Uma maneira de usar perl
:
Conteúdo de script.pl :
use warnings;
use strict;
use Archive::Tar;
## Check input arguments.
die qq[perl $0 <tar-file> <directory>\n] unless @ARGV == 2;
my $found_dir;
## Create a Tar object.
my $tar = Archive::Tar->new( shift );
## Get directory to search in the Tar object.
my $dir = quotemeta shift;
for ( $tar->get_files ) {
## Set flag and extract when last entry of the path is a directory with same
## name given as argument
if ( ! $found_dir && $_->is_dir && $_->full_path =~ m|(?i:$dir)/\Z|o ) {
$found_dir = 1;
$tar->extract( $_ );
next;
}
## When set flag (directory already found previously), extract all files after
## it in the path.
if ( $found_dir && $_->full_path =~ m|/(?i:$dir)/.*|o ) {
$tar->extract( $_ );
}
}
Ele aceita dois argumentos, um primeiro o arquivo TAR e outro o diretório a ser extraído. Corra como:
perl script.pl test.tar winbuild