du_tricks

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: RE: File size analyser utility
From: Gregory Hosler <gregory.hosler@eno.ericsson.se>
Date: Thu, 06 Jul 2000 10:32:52 +0800 (SGT)

On 05-Jul-00 Anurag Jalan wrote:
> Hi all,
> 
> On my Redhat box i have a 9 Gb HD with 4 primary partitions :
> 
> /boot - 50 Mb
> / - 6.5 Gb
> /home - 2.5 Gb
> and SWAP - 128 Mb
> 
> To my horror, I found that the /home partition is 89 % full.., despite the
> fact that i have only 10 users and my Web server is installed at
> /usr/local/apache ..
> 
> There are so many sub directories in the user directories that it is nearly
> impossible to scan all of them manually ..
> 
> Is there a utility that can help me locate the space hogs ?

start with du.

        as root:
                cd /home
                du -s *

This will tell you were the bulk lies. Then go into that directory
and repeat the du.

I also wrote a script that will do a du in a directory, and sort the
results, giving you a sorted list of usage.

        #!/bin/bash

        du -s * | awk '{printf("%6s %s\n", $1, $2)}' | sort

===

Subject: Re: File size analyser utility
From: russb@starpower.net
Date: Wed, 5 Jul 2000 23:05:12 -0400 (EDT)

On Wed, 5 Jul 2000, Anurag Jalan wrote:
> Is there a utility that can help me locate the space hogs ?

See if this works for you.

------------ CUT HERE --------------
#!/usr/bin/perl

# filename: /root/bin/diskhogs
# By Russell W. Behne - russb@starpower.net
# monitor user accounts for disk space

format top =
Username (UID)  Home Directory       Disk Space     Security
------------------------------------------------------------
.
format STDOUT =
@<<<<<<<<<<<<<  @<<<<<<<<<<<<<<<<    @<<<<<<<<<<    @<<<<<<<<
$uname,         $home_dir,           $disk,         $warn
.

open (PASSWD, "/etc/passwd") || die "Can't open passwd: $!\n";

USER:
while (<PASSWD>)  {
     chop;
     ($uname,$pass,$uid,$gid,$junk,$home_dir,$junk) = split(/:/);

if ($uname eq "root" || $uname eq "nobody" ||
     substr($uname,0,2) eq "uu" ||
     ($uid <= 100 && $uid > 0 )) { next USER; }
$warn = ($uid == 0 && $uname ne "root") ? "** UID=0" : "";
$warn = ($pass ne "!" && $pass ne "*") ? "** CK PASS" : $warn;

$uname .= " ($uid)";

if (-d $home_dir && $home_dir ne "/")
     {
     $du = `du -s -k $home_dir`;
     chop($du);
     ($disk,$junk) = split(/\t/,$du);
     $disk .= "K";
     }
else  { $disk = $home_dir eq "/" ? "skiped" : "deleted"; }
write;
}
exit;
------------ CUT HERE --------------

===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu