Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: See a quick view of folder-by-folder disk utilization' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: See a quick view of folder-by-folder disk utilization
Authored by: kmue on Oct 27, '03 03:26:47AM
Here is my attempt to sort and summarize the du(1) output. It works nicely across platforms.

#!/bin/sh
# sort output of du(1) and format it like GNU's "human readable format"
# and sum it up - km 20030716
#
awk=/usr/bin/awk
du=/usr/bin/du

$du -k $* | sort -rn | $awk '{
  t+=$1;
  if ($1>1024) {
    r=$1%1024; if (r!=0) { sz=($1-r)/1024 } else { sz=$1/1024 };
    print sz"M\t"$2;
  } else {
    print $1"K\t"$2;
  }
} END {
  if (t>1024) {
    r=t%1024; if (r!=0) { sz=(t-r)/1024 } else { sz=t/1024 };
    if (sz>1024) {
      r=sz%1024; if (r!=0) { ssz=(sz-r)/1024 } else { ssz=sz/1024 };
      print "Total: "ssz"G ("sz"M)";
    } else {
      print "Total: "sz"M ("t"K)";
    }
  } else {
    print t"K\tTotal";
  }
}'


[ Reply to This | # ]