//Tips tagged du
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
This piece of code lists the size of every file and subdirectory of the current directory, much like du -sch ./* except the output is sorted by size, with larger files and directories at the end of the list. Useful to find where all that space goes.

du -sk ./* | sort -n | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'

View Comments »

which directories and trees take up all the diskspace?
du -sm $(find /start/dir/* -type d -maxdepth 1 -xdev) | sort -g

If you want more human readable output try:
du -ha /var | sort -n -r | head -n 10

you want to see ALL directories in the tree
find $1 -type d | xargs du -sm | sort -g

To show all directories size including sub directories, type

du -h

To calculate the current directory size you are in (-s stand for summary)

du -sh

To show all the 1 level sub directories size (which you are not interested at sub sub directories.)

du -sh *

To show the size of specific directory

du -sh /home

To show the size of all sub directories of a specific directory

du -sh /home/*

View Comments »

Mail somebody about space running low in some path (ksh, bash):

PATHS="/export/home /home"
DU="/usr/bin/du -ks"
DF="/usr/bin/df -k"
for path in $PATHS
DISK_AVAIL=`$DF $path | $GREP -v "Filesystem" | $AWK '{print $5}'|$SED 's/%//g'`
if [ $DISK_AVAIL -gt 90 ];then
echo "Please clean up your stuff\n\n" > $MAILFILE
$CAT $MAILFILE | $MAILER -s "Clean up stuff" $mailto

View Comments »

The commmands below show the ten largest files/dirs in the working directory. Both commands give similar results, though handle things slightly differently. The 'du' option is good if you also need sizes of subdirectories, but the 'ls' option gives more detail.

ls -laSh | head -10

du -s * | sort -nr | head -10

I find both to be useful in situations where I need to make more free space.

View Comments »

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit