I need some help for this :
Let's say I am in a directory and in this directory there are other directories and files etc...
I would like to use a recursive function to count all the files and directories in it and in the sub too.
I know that I can solve the issue by using wc ... grep or find but I'm really trying to use my first recursive function here.
This is what I have done so far but it doesn't work properly
counting(){
for i in $(ls -a $1)
do
if [ -d $1/$i ];then
let d++
cd $1/$i
counting $i
cd ..
elif [ -f $1/$i ];then
let f++
fi
done
}
counting $1
echo "number of files = $f ; number of directories = $d"
$d
and$f
won't propagate upwards.