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__

In reply to rsyncsize -- Largest directories on a remote file system by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.