#!/usr/bin/perl use strict; use warnings; my $MAXCOUNT = 10; our $CVSVERSION = '$Revision: 1.2 $'; use File::Find; my $start_dir = $ARGV[0]; die "usage $0 start_dir" unless defined $ARGV[0] and -d $ARGV[0]; my @biggest = (); File::Find::find(sub { return if -l $_; return unless -f _; if(@biggest == $MAXCOUNT) { # Avoid a sort if it's too small anyway return if -s _ < $biggest[-1]->[1]; } push @biggest, [$File::Find::name, -s _]; @biggest = sort { $b->[1] <=> $a->[1] } @biggest; # Cut off at $MAXCOUNT splice @biggest, $MAXCOUNT if @biggest > $MAXCOUNT; }, $start_dir); # Report $MAXCOUNT largest files for(@biggest) { my($file, $size) = @$_; print "$file: $size\n"; } __END__ =head1 NAME spacehogs - Dig into a file hierarchy and determine the 10 biggest files =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS spacehogs start_dir =head1 DESCRIPTION B starts at a given start directory and drill down on it recursively, picking up the largest files it finds. When it's done, it'll report the 10 largest files in descending order. =head1 EXAMPLES spacehogs /tmp =head1 LEGALESE Copyright 2004 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2004, Mike Schilli