Advertisement
Guest User

dir_usage_script

a guest
Jun 14th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement