#!/bin/bash
#DESCR: create a list of files and dirs, sorted by size.
#DESCR: useful if you're asked to clean up a dir because the qtree is getting full
if [ $# -ne 0 -a -d "$1" ]
then
cd "$1"
fi
# extra names because stat on FC is more descriptive than on AS systems
du -akx . 2> /dev/null | fgrep -v './.snapshot' | while read SIZE FILENAME
do
STATTYPE=$(stat -c %F "$FILENAME" 2> /dev/null)
case "$STATTYPE" in
[Dd]irectory)
TYPE=d
;;
[Rr]egular?[Ff]ile|regular?empty?file)
TYPE=f
;;
[Ss]ymbolic?[Ll]ink)
TYPE=l
;;
Character?Device|character?special?device)
TYPE=c
;;
Block?Device|block?special?file)
TYPE=b
;;
[Ss]ocket)
TYPE=s
;;
Fifo?File|fifo)
TYPE=p
;;
*)
TYPE='?'
echo "unknown type $STATTYPE"
;;
esac
echo -e "$SIZE\t$TYPE\t$FILENAME"
done | sort -rn