Here is a tree script that was sent to me a while back. I modified it to use Korn shell and took out all the `expr` stuff and typeset some integer variables so the script would run a little faster.
#!/bin/ksh
###################
function search { #
###################
for dir in *
do
if [ -d $dir ] ; then # ==> If it is a directory (-d)...
dirLevel=0 # ==> Temp variable, keeping track of directory level.
while [ $dirLevel != $depth ] # Keep track of inner nested loop.
do
print -n "| " # ==> Display vertical connector symbol,
# ==> with 2 spaces & no line feed in order to indent.
(( dirLevel += 1 )) # ==> Increment dirLevel.
done
if [ -L $dir ] ; then # ==> If directory is a symbolic link...
print "+---$dir" `ls -l $dir | sed 's/^.*'$dir' //'`
# ==> Display horiz. connector and list directory name, but...
# ==> delete date/time part of long listing.
else
print "+---$dir" # ==> Display horizontal connector symbol...
# ==> and print directory name.
if cd $dir ; then # ==> If can move to subdirectory...
(( depth += 1 )) # ==> Increment depth.
search # with recursivity ;-)
# ==> Function calls itself.
(( numDirectories += 1 )) # ==> Increment directory count.
fi
fi
fi
done
cd .. # ==> Up one directory level.
if [ $depth ] ; then # ==> If depth = 0 (returns TRUE)...
dirFinished=1 # ==> set flag showing that search is done.
fi
(( depth -= 1 )) # ==> Decrement depth.
} # end of the search function
# - Main -
if [ $# = 0 ] ; then
cd `pwd` # ==> No args to script, then use current working directory.
else
cd $1 # ==> Otherwise, move to indicated directory.
fi
print "Initial directory = `pwd`"
dirFinished=0 # ==> Search finished flag.
typeset -i depth=0 # ==> Depth of listing.
typeset -i numDirectories=0
typeset -i dirLevel=0
while [ $dirFinished != 1 ] # While flag not set...
do
search # ==> Call function after initializing variables.
done
print "Total directories = $numDirectories"
This is not my script, although I could write it myself. The copy I got doesn't have the author's name on it, but he was a pretty good script writer. This is a nice shell. You can add some additional counters, remove the tree stuff, test for a link test -L and a file test -f and you should be able to get a decent report.
Jerry