How to count the number of folders in a specific directory. I am using the following command, but it always provides an extra one.
find /directory/ -maxdept         
        I think the easiest is
  ls -ld images/* | wc -l
where images is your target directory. The -d flag limits to directories, and the -l flag will perform a per-line listing, compatible with the very familiar wc -l for line count.
Some useful examples:
count files in current dir
/bin/ls -lA  | egrep -c '^-'
count dirs in current dir
/bin/ls -lA  | egrep -c '^d'
count files and dirs in current dir
/bin/ls -lA  | egrep -c '^-|^d'
count files and dirs in in one subdirectory
/bin/ls -lA  subdir_name/ | egrep -c '^-|^d'
I have noticed a strange thing (at least in my case) :
When I have tried with
lsinstead/bin/lsthe-Aparameterdo not list implied . and ..NOT WORK as espected. When I uselsthat show ./ and ../ So that result wrong count. SOLUTION :/bin/lsinsteadls
No of directory we can find using below command
ls -l | grep "^d" | wc -l
Best way to navigate to your drive and simply execute
ls -lR | grep ^d | wc -l
and to Find all folders in total, including subdirectories?
find /mount/point -type d | wc -l
...or find all folders in the root directory (not including subdirectories)?
find /mount/point -maxdepth 1 -type d | wc -l
Cheers!
find . -mindepth 1 -maxdepth 1 -type d | wc -l
For find -mindepth means total number recusive in directories
-maxdepth means total number recusive in directories
-type d means directory
And for wc -l means count the lines of the input
Best way to do it:
ls -la | grep -v total | wc -l
This gives you the perfect count.