in reply to Re^4: <p>Directory used % in Linux </p>
in thread Directory used % in Linux
As I already pointed out, the "du" tool can help you with this by reporting directory sizes but you will have to calculate percentages yourself.
Here's an example that does pretty much what you describe, go ahead and hammer it into the shape you want:
#!/usr/bin/perl use strict; use warnings; my $dir = join(' ', map { '"'.$_.'"' } @ARGV) || "*"; # Use arguments +or default to pwd my @lines = qx(du -sc $dir); # Get sizes in bytes, with total my ($total) = split(/\s/, pop @lines); # Get total number of bytes foreach my $line (@lines) { if ($line =~ /(\d+)/) { printf("%6.2f%%\t%s", $1 * 100 / $total, $line); # Prefix % } }
Time flies when you don't know what you're doing
|
|---|