DUSORT
TAG_ADS
#!/usr/bin/perl -w
use strict;

###############################################################
# DUSORT - Enhanced 'du' script
# Version 0.1
# Copyleft 2005 - Nathan E. Pralle
#
# DESCRIPTION:  The standard utility 'du' is darn handy, but I've
# always wanted a way to have it sorted by size, yet still have
# it display human-readable format.  So, I wrote this little Perl
# script to 'enhance' the du utility.
#
# SYNTAX:    dusort
#
# CONTACT:   Questions?  Comments?
#            http://www.nathanpralle.com/contact.html
#################################################################

my %duhash;

open(DU,"du -S |");
while(<DU>){	
        chomp;
        my($size,$dir)=split(/\s+/,$_,2);
        $duhash{$dir}=$size;
}
close(DU);

foreach my $key (sort hashValueAscendingNum(keys(%duhash))){
        print reformatSize($duhash{$key})."  $key\n";
}

exit;

sub hashValueAscendingNum {
   $duhash{$a} <=> $duhash{$b};
}

sub reformatSize{
        my $done;
        my $size=shift;
        if($size<1024){
                return "$size B";
        }
        elsif($size>=1024 && $size<1048576){
                $size=$size/1024;
                return sprintf("%0.1f MB",$size);
        }
        else{
                $size=$size/1048576;
                return sprintf("%0.1f GB",$size);
        }
}


This page and all content (C)2002-2004 Nathan E. Pralle.
www.nathanpralle.com
Unauthorized distribution is prohibited except with written permission of the author.