#!/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 % } }