Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

dir_usage_script

By: a guest on Jun 14th, 2012  |  syntax: Bash  |  size: 0.84 KB  |  hits: 80  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. #DESCR: create a list of files and dirs, sorted by size.  
  4. #DESCR: useful if you're asked to clean up a dir because the qtree is getting full
  5.  
  6. if [ $# -ne 0 -a -d "$1" ]
  7. then
  8.     cd "$1"
  9. fi
  10.  
  11. # extra names because stat on FC is more descriptive than on AS systems
  12. du -akx . 2> /dev/null | fgrep -v './.snapshot' | while read SIZE FILENAME
  13. do
  14.         STATTYPE=$(stat -c %F "$FILENAME" 2> /dev/null)
  15.         case "$STATTYPE" in
  16.         [Dd]irectory)
  17.                 TYPE=d
  18.                 ;;
  19.         [Rr]egular?[Ff]ile|regular?empty?file)
  20.                 TYPE=f
  21.                 ;;
  22.         [Ss]ymbolic?[Ll]ink)
  23.                 TYPE=l
  24.                 ;;
  25.         Character?Device|character?special?device)
  26.                 TYPE=c
  27.                 ;;
  28.         Block?Device|block?special?file)
  29.                 TYPE=b
  30.                 ;;
  31.         [Ss]ocket)
  32.                 TYPE=s
  33.                 ;;
  34.         Fifo?File|fifo)
  35.                 TYPE=p
  36.                 ;;
  37.         *)
  38.                 TYPE='?'
  39.                 echo "unknown type $STATTYPE"
  40.                 ;;
  41.         esac
  42.  
  43.         echo -e "$SIZE\t$TYPE\t$FILENAME"
  44. done | sort -rn