How can I count the number of folders in a drive using Linux?

  • Find all folders in total, including subdirectories:

    find /mount/point -type d | wc -l
    
  • Find all folders in the root directory (not including subdirectories):

    find /mount/point -maxdepth 1 -mindepth 1 -type d | wc -l
    

    The -maxdepth 1 confines the command to the current directory (i.e., it forbids recursion); the -mindepth 1 causes it not to include the top-level directory (the mount point) itself.


Navigate to your drive (Can open a terminal window there) and simply execute:

ls -lR | grep ^d | wc -l

Newlines are valid characters in directory names. I suggest letting find print a character for each directory found and then letting wc count those characters:

find /mount/point -type d -printf 'a' | wc -c