How to show disk space in human readable format DU

Hello, folks.Is there any trick to display disk space in human readable format in Solaris 8, 9, & 10 using DU -h like that of Linux?Please advise.Thanks a lot!
[191 byte] By [webofficera] at [2007-11-27 9:55:23]
# 1
man du
alan.paea at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 2
you can use df -h for the mount points in human readable format. For du I like to use du -h | sort -nr | more
AdamRichardsa at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 3
My question was actually how to display slice/folder size in GB or MB in Solaris 8 or older.I know that Solaris 8 or older does not have the h option.That was why I asked if there was any other tool can accomplish that either using du in combination with another utility.
webofficera at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 4

Download teh coreutils package from sunfreeware.com. It contains they GNU version of du, with the -h switch. You will need to ether modify your PATH or set up an alias since the native Solaris version is in /usr/bin and it will get executed first unless you change your PATH or set up an alias.

bosconeta at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 5

Try the following, thanks to the book Wicked Cool Shell Scripts:

http://www.intuitive.com/wicked/

#!/bin/sh

# newdf - a friendlier version of df

sedscript="/tmp/newdf.$$"

trap "rm -f $sedscript" EXIT

cat << 'EOF' > $sedscript

function showunit(size)

{ mb = size / 1024; prettymb=(int(mb * 100)) / 100;

gb = mb / 1024; prettygb=(int(gb * 100)) / 100;

if ( substr(size,1,1) !~ "[0-9]" ||

substr(size,2,1) !~ "[0-9]" ) { return size }

else if ( mb < 1) { return size "K" }

else if ( gb < 1) { return prettymb "M" }

else { return prettygb "G" }

}

BEGIN {

printf "%-27s %7s %7s %7s %8s %-s\n",

"Filesystem", "Size", "Used", "Avail", "Capacity", "Mounted"

}

!/Filesystem/ {

size=showunit($2);

used=showunit($3);

avail=showunit($4);

printf "%-27s %7s %7s %7s %8s %-s\n",

$1, size, used, avail, $5, $6

}

EOF

df -k | gawk -f $sedscript

exit 0

NivenDa at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 6

hi webofficer

take the advice of bosconet and get the GNU-version. maybe the "ncdu", based on ncurses could be worth a try, too. it can also be found at sunfreeware.com.

and a weired suggestion: ever tried, to replace the solaris8-"du" with one from a solaris9 machine ? ;-)

cannot evaluate this, becaus i've got no sol8, but on my linux-boxes that trick works with some commands (with others not... *gg* )

cheers, jenny

************************

the sweater of a woman fits perfect,

when the men gasp for air. ;-)

Jenny_Sa at 2007-7-13 0:25:21 > top of Java-index,Solaris Operating System,Solaris 10 Features...