-1

I have to count all executable files- done it and count files which are .sh files- no idea how to do it. Any help? Here's my code:

c=0
d=0
    for f in /home/lenovo/*; do
        if [ -x "$f" ] ; then
           c=$(($c+1))
           if $f . name -iname = '*.sh'; then
             d=$(($d+1))
           fi
        fi
    done
    echo $c
    echo $d
ktoś tam
  • 1
  • 1

2 Answers2

1

With a correct find command, you can do a correct and quick way to do this, for example :

find . -type f -name "*.sh"|wc -l

And you can set more arguements in find to be more efficient (for example -maxdepth -mindepth or -ctime or -executable or -perm that could be intersting too in you use case)

YLR
  • 1,503
  • 4
  • 21
  • 28
0

Could it be as simple as ls /home/lenovo/*.sh | wc -c? Or do you have other requirements?

This would count any file ending with .'sh' whether it is executable or not.

mattb
  • 2,787
  • 2
  • 6
  • 20