0

I have a recursive function (mandatory that it's recursive) that travels through directories and looks at type of files (dir, file, sock, pipe, char, block, or link), but I don't know what approach to take. I was thinking something with global variables:

count(){
   for path in "$1"/*;do

        if [ -d "$path" ];then
            ndir=$((ndir+1))
            count "$path" 
                        continue
        fi
        if [ -L "$path" ];then
            nlink=$((nlink+1))
            continue            
        fi
            if [ -c "$path" ];then
            nchar=$((nchar+1))
            continue
        fi  

            ....

}

ndir=0
nfile=0
nsock=0
npipe=0
nchar=0
nblock=0
nlink=0

count $filename

printf "%d %d %d %d %d %d %d" $ndir $nfile $nsock $nblock $nlink $nchar $npipe

Would something like this work?

Evan
  • 2,400
  • 1
  • 18
  • 34
jabk
  • 1,388
  • 4
  • 25
  • 43

0 Answers0