| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# show sorted content of tar archive |
| 4 |
|
| 5 |
$0 =~ s:.*/::; |
| 6 |
|
| 7 |
$usage = "usage: $0 file.tar\n"; |
| 8 |
die $usage if scalar(@ARGV) != 1 or "@ARGV" =~ /^-/; |
| 9 |
|
| 10 |
$file = shift @ARGV; |
| 11 |
|
| 12 |
die "$0: \"$file\" does not exist\n" unless -e $file; |
| 13 |
die "$0: \"$file\" is not a regular file\n" unless -f $file; |
| 14 |
die "$0: \"$file\" is not readable\n" unless -r $file; |
| 15 |
|
| 16 |
open $list,'-|',qw'tar tvf',$file or exit $?; |
| 17 |
|
| 18 |
while (<$list>) { |
| 19 |
if (/(.+?) (.+?) +(\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d) (.+)/) { |
| 20 |
$p{$5} = $1; |
| 21 |
$u{$5} = $2; |
| 22 |
$s{$5} = $3; |
| 23 |
$d{$5} = $4; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
foreach $f (sort keys %p) { |
| 28 |
printf "%s %-17s %13d %s %s\n",$p{$f},$u{$f},$s{$f},$d{$f},$f; |
| 29 |
} |