[HPADM] RE: [SUMMARY] root near to 89%

From: Hustert Klaus-CKH035 (Klaus.Hustert@motorola.com)
Date: Thu Sep 18 2003 - 09:31:39 EDT


Special thanks to Bill Hassel for this input:
=============================================
Don't look for big files! While there may be a few, you likely have directories that are in the wrong place (under /, not /opt). Use this command to find the big directories:

du -kx / | sort -rn > /var/tmp/du.root

NOTE: /dev should be perhaps 15-25 kbytes. If it is very large, someone created a regular file in /dev, usually a spelling error.

OLD SUMMARY:
============

Thanks to all who has respond and so really fast they did!

The key answer is the param -xdev for the find command I think.

The answer I got mostly was `find / -xdev -size +100000c -print`

Some variations:
find / -xdev -type f -exec du -k {} \; | sort -n
find / -xdev -size +1000 -exec ll -d {} \;

But also the others are from interrest:
find / -fstype hfs -type f -exec ls -l {} \;
du / | sort -n
du -sk * | sort -nr | head -nn (where nn is a number of files you want to report back. 10 is a good start point...) cd /;du -akx * | sort -rn | more

Or some perl scripts:

First:

#!/usr/bin/ksh
#
# bigger <size_in_mbyte>
#
# Show the files bigger then a given value in MB, sorted by size. # Performs the search starting from current directory
# and only in current filesystem (thanks to -xdev).
#
# Stefano at Unternaehrer dot net

if test $1 && test $1 -gt 0
then
        GRAND=$1
        BYTES=`echo ${GRAND}*1024*1024 | bc`
        echo
        pwd
        echo Files bigger than $GRAND MB in current FS:
        echo
        FNAMES=`find . -xdev -size +${BYTES}c`

        if test -n "$FNAMES"
        then
                ls -Al ${FNAMES} | sort +4nr
        else
                echo -- nothing --
        fi
        echo
else
        echo
        echo "usage: bigger size_in_megabytes"
        echo " ex: bigger 10"
        echo
fi

Second:
- - - - - snip - - - - -
#!/usr/bin/perl
#
# 06/03 wht; v1.20: Made verbose the default output and added the -s option # 06/03 wht; v1.10: Added verbose (-v) option # 06/03 wht; v1.00: Created
#*****************************************************************************
# fbig
#*****************************************************************************
#
# PURPOSE
# find big files
#
# SYNTAX
# fbig [ -s ] [ starting_directory ]
#
# OPTIONS
# -s size only (or "simple") output
#
# starting_directory
# directory to start looking for files.
# default is the current directory
#
#*****************************************************************************
#

$CMD = $0; # full program name as it was called
$0 =~ s:^.*/::; # program name sans directory info
$VERSION = "1.00"; # version

$FALSE = 0; # FALSE
$TRUE = 1; # TRUE

# month number to name hash
%NUM_TO_MONTHS = (
    0 => "Jan", 1 => "Feb", 2 => "Mar",
    3 => "Apr", 4 => "May", 5 => "Jun",
    6 => "Jul", 7 => "Aug", 8 => "Sep",
    9 => "Oct", 10 => "Nov", 11 => "Dec",
);

#-----------------------------------------------------------------------------
# Main Routine
#
# Note: The main routine is simply a wrapper for the real script so the
# output can be piped through "more".
#
FBig: {

    # if the first argument on the command line is "==Run_FBig==" then
    # drop the "==Run_FBig==" argument and call the real code.
    if ( $ARGV[0] eq "==Run_FBig==" ) {

        shift(@ARGV);

        Run_FBig();

    } #END if ( $ARGV[0] eq "==Run_FBig==" )

    # otherwise, recall the command adding the "==Run_FBig==" argument
    # and pipe the output through more.
    else {

        system("$CMD '==Run_FBig==' @ARGV | /bin/more -e");

    } #END else

} #END FBig

#-----------------------------------------------------------------------------
# Run_FBig
# This is the real code
#
sub Run_FBig {

    # default is verbose output
    $VERBOSE = $TRUE;

    # turn off verbose output if -s was specified
    if ( @ARGV[0] eq "-s" ) { $VERBOSE = $FALSE; shift(@ARGV); }

    # get starting directory
    $starting_dir = Get_Starting_Directory();

    # get a list of files
    # o files only - no directories, links, special files, etc.
    # o use xdev to stay inside the current filesystem
    # o reverse sort so when the second reverse sort is performed,
    # files of the same size will appear in alphabetical order
    foreach $file ( reverse(sort(qx(/bin/find $starting_dir -xdev -type f -print))) ) {

        # get rid of the trailing newline
        chomp($file);

        # use stat to get the file size
        ($mode,$uid,$gid,$size,$mtime) = (lstat($file))[2,4,5,7,9];

        # create a unique key (for multiple files of the same size)
        $i = 0;

        do {
            $key = sprintf "H%20s%.10d", $size, $i; $i++;
        } until ( ! defined($file{$key}) );

        # save the file name other important info
        $file{$key} = $file;

        $mode{$key} = $mode;
        $uid{$key} = $uid;
        $gid{$key} = $gid;
        $size{$key} = $size;
        $mtime{$key} = $mtime;

    } #END foreach $file ( reverse(sort(qx(/bin/find $starting_dir -xdev -type f -print))) )

    # could find zero regular files in a directory path so output
    # a small message rather than just returning to the command prompt
    if ( ! defined(%file) ) {

        print "no files found\n";
        return();

    } #END if ( ! defined(%file) )

    if ( $VERBOSE ) {

        # create UID to user name hash
        while ( ($name,$uid) = (getpwent)[0,2] ) { $user{$uid} = $name unless ( defined($user{$uid}) ); }

        # create GID to group name hash
        while ( ($name,$gid) = (getgrent)[0,2] ) { $group{$gid} = $name unless ( defined($group{$uid}) ); }

        # compute the epoch time of six months ago
        # => current epoch time minus half the number of seconds in a year (365 days)
        $six_months_ago = time() - 15768000;

        # sort the output by file size/file name
        foreach $key ( reverse(sort(keys(%file))) ) {

            printf "-%9s %-8s %-8s %11s %12s %s\n",
                    Get_Attr($mode{$key}),
                    defined($user{$uid{$key}}) ? $user{$uid{$key}} : $uid{$key},
                    defined($group{$gid{$key}}) ? $group{$gid{$key}} : $gid{$key},
                    Add_Commas($size{$key}),
                    Format_Time($mtime{$key}),
                    $file{$key};

        } #END foreach $key ( reverse(sort(keys(%file))) )

    } #END if ( $VERBOSE )

    else {

        # sort the output by file size/file name
        foreach $key ( reverse(sort(keys(%file))) ) {

            printf "%15s %s\n", Add_Commas($size{$key}), $file{$key};

        } #END foreach $key ( reverse(sort(keys(%file))) )

    } #END else

} #END Run_FBig

#-----------------------------------------------------------------------------
# Get_Starting_Directory
# Determines the starting directory
#
sub Get_Starting_Directory {

    # if the user specified a directory on the command line...
    if ( defined($ARGV[0]) ) {

        # error if not a directory
        die "$0: $ARGV[0] is not a directory\n" unless ( -d $ARGV[0] );

        return($ARGV[0]);

    } #END if ( defined($ARGV[0]) ) {

    return(".");

} #END Get_Starting_Directory

#-----------------------------------------------------------------------------
# Get_Attr
# Turn octal permissions into text attributes
#
# Local Vars
# $mode permissions in octal form
# $bits permissions converted to a binary string of characters
#
# Notes
# 4000 (= u=s) Set user ID on file execution (file only)
# 2000 (= g=s) Set group ID on file execution (file only)
# 1000 (= u=t) Set sticky bit
# 0400 (= u=r) Read by owner
# 0200 (= u=w) Write by owner
# 0100 (= u=x) Execute (search in directory) by owner
# 0040 (= g=r) Read by group
# 0020 (= g=w) Write by group
# 0010 (= g=x) Execute/search by group
# 0004 (= o=r) Read by others
# 0002 (= o=w) Write by others
# 0001 (= o=x) Execute/search by others
#
sub Get_Attr {
    my($mode) = shift;

    # convert octal mode to a binary string of characters
    my $bits = unpack("B32", pack("N", $mode));

    # get the attributes for the owner
    $attr = Gen_Attr_String(substr($bits,-12,1),"s",substr($bits,-9,1),substr($bits,-8,1),substr($bits,-7,1));

    # get the attributes for the group
    $attr .= Gen_Attr_String(substr($bits,-11,1),"s",substr($bits,-6,1),substr($bits,-5,1),substr($bits,-4,1));

    # get the attributes for the world
    $attr .= Gen_Attr_String(substr($bits,-10,1),"t",substr($bits,-3,1),substr($bits,-2,1),substr($bits,-1,1));

    return($attr);

} #END Get_Attr

#-----------------------------------------------------------------------------
# Gen_Attr_String
# Generate the attribute string
#
# Local Vars
# $special special bit
# $s_or_t character to output (s or t) if $special is set to
1
# $read read bit
# $write write bit
# $execute execute bit
#
# $char1 first character of attribute string
# $char2 second character of attribute string
# $char3 third character of attribute string
#
sub Gen_Attr_String {
    my($special,$s_or_t,$read,$write,$execute) = @_;
    my($char1,$char2,$char3);

    # output a dash unless otherwise set
    $char1 = $char2 = $char3 = "-";

    # set the rwx characters
    $char1 = "r" if ( $read );
    $char2 = "w" if ( $write );
    $char3 = "x" if ( $execute );

    # set special flag if special bit is 1
    if ( $special ) {

        # set the execute character to an s or t
        $char3 = $s_or_t;

        # change the character to uppercase if the execute bit is not set
        $char3 = uc($char3) unless ( $execute );

    } #END if ( $special )

    # return the full attribute string
    return ("${char1}${char2}${char3}");

} #END Gen_Attr_String

#-----------------------------------------------------------------------------
# Add_Commas
# Add commas to numbers in a string
#
sub Add_Commas {
    my($string) = shift;

    # reverse the string
    $string = reverse($string);

    # add commas to the numbers in the string
    $string =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;

    # reverse string again
    return(scalar(reverse($string)));

} #END Add_Commas

#-----------------------------------------------------------------------------
# Format_Time
# format the mtime of a file
#
# Local Vars
# $mtime mtime of a file in epoch seconds
# $min minute
# $hour hour
# $day day
# $month month
# $year year
#
sub Format_Time {
    my($mtime) = shift;
    my($min,$hour,$day,$mon,$year);

    # convert epoch mtime to month, day, year, hour, and minute
    ($min,$hour,$day,$month,$year) = (localtime($mtime))[1..5];

    # if file is more than six months old...
    if ( $mtime < $six_months_ago ) {

        # show mtime in month, day, year
        return(sprintf "%s %2d %4d", $NUM_TO_MONTHS{$month}, $day, $year + 1900);

    } #END if ( $mtime < $six_months_ago )

    # if file is less than six months old...
    else {

        # show the mtime in month, day, hour, minute
        return(sprintf "%s %2d %.2d:%.2d", $NUM_TO_MONTHS{$month}, $day, $hour, $min);

    } #END else

} #END Format_Time
- - - - - snip - - - - -

Thanks again,
Klaus

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)
--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:34 EDT