|< 1 2 >| | 13 Einträge, 2 Seiten |
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Getopt::Std;
my %opts = ();
getopts('d:rh', \%opts);
print usage() if(!defined $opts{'d'} or $opts{'h'});
my @du = qx(du -h --max-depth=1 $opts{'d'});
my %d = ();
foreach(@du) {
chomp;
if(/(\d+)K(.*)$/) { $_ = ($1 *1024)." ".$2; }
if(/(\d+)M(.*)$/) { $_ = ($1 *1024*1024)." ".$2; }
if(/(\d+)G(.*)$/) { $_ = ($1*1024*1024*1024)." ".$2; }
if(/(\d+) (.*)$/) { push @{$d{$1}}, $2; }
}
@du = ();
foreach (sort {$a <=> $b} keys %d) {
my $key = $_;
if ($_ > 1073741824) { $key = ($key / 1073741824)."G"; }
elsif($_ > 1048576) { $key = ($key / 1048576) ."M"; }
elsif($_ > 1024) { $key = ($key / 1024) ."K"; }
foreach my $ele (@{$d{$_}}) {
push @du, $key."\t".$ele;
}
}
if($opts{'r'}) {
print $_."\n" foreach(reverse @du);
} else {
print $_."\n" foreach(@du);
}
sub usage {
print<<EOF;
du.pl -d <directory> [-r]
Arguments:
mandatory:
-d directory name
optional:
-r if the sort order should be descending
EOF
exit 0;
}
|< 1 2 >| | 13 Einträge, 2 Seiten |