#!perl # see http://www.perlmonks.org/?node=rsyncsize use strict; use warnings; use List::Util "min"; my $g = $ARGV[0] or die q (rsyncsize.pl -- utility to find which directories and files use the most disk space on a remote file system accessed by rsync. Usage: perl rsyncsize.pl host:path or host::path or any other form of pathname rsync accepts ); open my $R, "-|", qw"rsync -zr", $g or die "error executing rsync"; my %h; my $c = 0; while(<$R>){ if (!/^\S{10}/) { warn $_; next; } $c++; chomp; my $n = substr $_,43; substr($_,11) =~ /^\s*(\d+)/ or die; my $s = $1; while ($n =~ m"/|$"g) { my $p = $`; $h{$p} += $s; } } close $R or die "error from rsync"; warn "got $c files listed"; my @m = sort { $h{$b} <=> $h{$a} } keys%h; for my $n (reverse @m[0 .. min(@m-1,9999)]) { printf "%10.0f %s\n", $h{$n}, $n; } __END__