#!/usr/bin/perl # fs.pl # Find filespace consumption per user for a given directory tree # # USAGE # perl fs.pl dir1 [dir2 ... dirN] use warnings; use strict; use File::Find; my %sum; # Add the size of a file to a tally for the file owner. sub wanted_user { my ($user,$size) = (stat($_))[4,7] or die "can't stat '$_': $!\n"; $sum{$user} += $size; } # MAIN EXECUTION while (<@ARGV>) { my $dir = $_; find (\&wanted_user, $dir); print "Usage Report for '$dir'\n"; print "USER\t USAGE\n"; foreach my $user (sort keys %sum) { printf "%s:\t%.2fMB\n", $user, $sum{$user}/1024/1024; } }