Linux command to count the number of directories in a specific directory
To count total number of directories within specific directory you have to go to one step back from the directory you want to count.
For example you have to count number of modules in modules folder on path /sites/all/modules. First navigate to folder /sites/all and then run the below command :
ls -l modules | grep -c ^d
where "modules" is the name of the folder inside which you need to count directories.