[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: script/app to compile statistics about disk usage? >one line



On Sat, Jul 31, 2004 at 08:47:47AM -0700, Matt Perry wrote:
> 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{$_}, $_;
> }
> 

My one liner is:

du / | sort -k 1,1nr | most

The sort gives a listing of du output in descending numerical order,
so the largest objects are at the top. The very largest object is /,
since everything else sits under it.  If you run this as a user, you
get a bunch of error messages as it passes over the /proc system. If
you run this as root, those messages go away, and instead you get a
bunch of zero length at the end of the list.

(most is a better less. you can use less if you don't want to install
most.)

-- 
Paul E Condon           
pecondon@mesanetworks.net



Reply to: