27649a1e19b26856dd9b435fba457f71067526f7
[platform/upstream/bash.git] / examples / scripts / vtree2
1 #!/bin/bash
2 #
3 # vtree - make a tree printout of the specified directory, with disk usage
4 #         in 1k blocks
5 #
6 # usage: vtree [-a] [dir]
7 #
8 # Original posted to Usenet sometime in February, 1996
9 #
10 usage()
11 {
12         echo "vtree: usage: vtree [-a] [dir]" >&2
13 }
14
15 while getopts a opt
16 do
17         case "$opt" in
18         a)      andfiles=-a ;;
19         *)      usage ; exit 2 ;;
20         esac
21 done
22
23 shift $((OPTIND - 1))
24
25 export BLOCKSIZE=1k     # 4.4 BSD systems need this
26
27 [ $# -eq 0 ] && set .
28
29 while [ $# -gt 0 ]
30 do
31         cd "$1" || { shift; [ $# -ge 1 ] && echo >&2; continue; }
32         echo -n "$PWD"
33
34         du $andfiles | sort +1f | sed \
35                 's/\([^ ]*\)    \(.*\)/\2  (\1)/
36                 '"s#^$1##"'
37                 s#[^/]*/\([^/]*\)$#|____\1#
38                 s#[^/]*/#|    #g'
39         
40         [ $# -gt 1 ] && echo 
41         shift
42 done