Re: script/app to compile statistics about disk usage?
On Fri, 30 Jul 2004, Silvan wrote:
> cooked up. What I want to do is look at my disks and gather statistics about
> what is eating the most space. Where the biggest files are, which
> directories are the largest, etc.
What I do to see large directories is just 'du -sh *' starting at root and
then drilling down from there. If you want to see what the largest files
are, you can use this Perl script that Randal Schwartz wrote:
#!/usr/bin/perl
#
# Usage: bigfiles <dir> [dir ...]
#
# Abstract: This script reports the top 20 largest files in one or
# more specified directories, including subdirectories.
#
# By: Randal Schwartz <merlyn@stonehenge.com>
# From the article at
# http://www.stonehenge.com/merlyn/UnixReview/col16.html
if ($#ARGV lt 0) {
$0 =~ s#.*/##;
print("Usage: $0 <dir> [dir ...]\n");
exit 1;
}
use File::Find;
find (sub {
$size{$File::Find::name} =
-s if -f;
}, @ARGV);
@sorted = sort {
$size{$b} <=> $size{$a}
} keys %size;
splice @sorted, 20 if @sorted > 20;
foreach (@sorted) {
printf "%10d %s\n", $size{$_}, $_;
}
Reply to: