Hello,
I have written this little script in order to find the biggest file size, recursively.
I would like to modify it in order to find the 'n' biggest files.
'n' would be an argument on the command line (1 by default).
How could I achieve that efficiently ? With a 2 dimensional-array ?
Thank you.
#!/usr/bin/perl -w
use strict;
use Cwd;
use File::Find;
no warnings 'File::Find';
my ($max,$name,$n) = (0,0,0);
sub scanfile {
return unless -f; # only files
return unless -r; # readable
return if -l; # not symlinks
$n++;
print "." unless ($n % 400); # "progress bar"
my $sz = -s;
if ($max < $sz) { # save biggest
$max = $sz;
$name = $File::Find::name;
}
}
print "Scanning...";
$|=1; # flush output
find(\&scanfile, cwd); # start in current directory recursively
printf("\nBiggest: %d kb %s\n",$max/1024,$name);