Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello everybody!!
I hope anyone can help me with this problem:
I need to elaborate a script that evaluate de content on the actual directory and print an executive resume on what is inside about files, directories, links and special objects, like:
/user/home/director: 10 files, 8 directories, 5 links, 0 special objects.If there are included arguments these has to correspond to a system directories. In this case the script should evaluate each one of those directories and show a resume of each one of them

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.
fiprint "Initial directory = `pwd`"
dirFinished=0 # ==> Search finished flag.
typeset -i depth=0 # ==> Depth of listing.
typeset -i numDirectories=0
typeset -i dirLevel=0while [ $dirFinished != 1 ] # While flag not set...
do
search # ==> Call function after initializing variables.
doneprint "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

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |