Leser: 22
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
#!/usr/bin/perl use strict; use warnings; use File::Find; use File::stat; print format_size( dir_usage('/home') )."\n"; #dir usage sub dir_usage { my $summ=0; find(sub { my $file=$File::Find::name; return if($file eq '.' || $file eq '..'); $summ+=stat($file)->size(); },@_); return $summ; } # format size sub format_size { my $size=shift || 0; my @formats=qw(Byte Kb Mb Gb Tb Pb); while($size>=1024 && @formats>1) { shift(@formats); $size/=1024; } return sprintf('%.02f %s',$size,$formats[0]); }