To find the directories and files taking the most disk space on a local disk, you can use du -a pathname | sort -n. This script is an approximation of the same thing for a remote system you can only access through rsync.
The original purpose of this script was to find the largest modules and authors on CPAN – you can see some sample output there. You can use this script for that too: just download this code as rsyncsize.pl, then run perl rsyncsize.pl cpan.pair.com::CPAN/ > sizes and examine sizes.
#!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__
|
|---|