Hier ein einfacher Schnellschuß, der auf Linux laufen sollte (und die Linux-Tools
tree und
du benutzt):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use strict;
use warnings;
my %cmd = (
tree => '/usr/bin/tree -df',
du => '/usr/bin/du -sh'
);
sub add_size {
my $dir = shift;
if ( my $result = qx{ $cmd{du} $dir } ) {
chomp $result;
$result = join " ", reverse( split( m{\s+}, $result, 2 ) );
return $result . "\n";
}
else {
warn "'$cmd{du} $dir' failed: $!\n";
return $dir;
}
}
for my $dir ( @ARGV ) {
open my $pipe, '-|', "$cmd{tree} $dir" or die "pipe to $cmd{tree} failed: $!\n";
while ( my $line = <$pipe> ) {
$line =~ s{(\Q$dir\E.+)\n}{add_size($1)}xe;
print $line;
}
close $pipe;
}
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!