Patch-ID: bash40-021
[bash.git] / examples / scripts / vtree2
blob878cbabc26a6c71dae04037093d1fbdae34b6a23
1 #!/bin/bash
3 # vtree - make a tree printout of the specified directory, with disk usage
4 # in 1k blocks
6 # usage: vtree [-a] [dir]
8 # Original posted to Usenet sometime in February, 1996
9 # I believe that the original author is Brian S. Hiles <bsh29256@atc.fhda.edu>
11 usage()
13 echo "vtree: usage: vtree [-a] [dir]" >&2
16 while getopts a opt
18 case "$opt" in
19 a) andfiles=-a ;;
20 *) usage ; exit 2 ;;
21 esac
22 done
24 shift $((OPTIND - 1))
26 export BLOCKSIZE=1k # 4.4 BSD systems need this
28 [ $# -eq 0 ] && set .
30 while [ $# -gt 0 ]
32 cd "$1" || { shift; [ $# -ge 1 ] && echo >&2; continue; }
33 echo -n "$PWD"
35 du $andfiles | sort -k 2f | sed \
36 -e 's/\([^ ]*\) \(.*\)/\2 (\1)/' \
37 -e "s#^$1##" \
38 -e 's#[^/]*/\([^/]*\)$#|____\1#' \
39 -e 's#[^/]*/#| #g'
41 [ $# -gt 1 ] && echo
42 shift
43 done