In order to just get the count of the number of directories (folders) at a location you would need to use multiple commands in conjunction.
Commands to be used to display the list of files/directories
- ls -l
- grep '^d.*'
- wc -l
If you use the ls command it will just display the list of files and directories at the given location. The trick here is used ls with option -l to display the list in long form.
Example:ls -l
total 0
drwxr-xr-x 7 code2care staff 224 May 13 19:46 AndroidStudioProjects
drwx------@ 3 code2care staff 96 Feb 13 16:04 Applications
drwxr-xr-x 4 code2care staff 128 Jan 17 16:16 ClassRoom
drwx------@ 9 code2care staff 288 Jun 26 12:57 Desktop
drwx------@ 13 code2care staff 416 Jun 5 17:11 Documents
drwx------+ 36 code2care staff 1152 Jun 26 12:56 Downloads
drwxr-xr-x 9 code2care staff 288 Apr 24 17:11 IdeaProjects
drwx------@ 76 code2care staff 2432 Apr 13 16:39 Library
drwx------ 6 code2care staff 192 Mar 20 16:54 Movies
drwx------+ 7 code2care staff 224 Mar 13 22:42 Music
drwx------+ 4 code2care staff 128 Jan 2 23:28 Pictures
drwxr-xr-x+ 4 code2care staff 128 Jan 2 23:03 Public
drwxr-xr-x 6 code2care staff 192 Jun 5 15:03 PycharmProjects
drwxr-xr-x 4 code2care staff 128 May 15 12:22 eclipse
drwxr-xr-x 4 code2care staff 128 May 15 13:07 eclipse-workspace
drwx------ 11 code2care staff 352 Apr 3 14:57 iCloud Drive (Archive)
drwxr-xr-x 2 code2care staff 64 Jun 5 17:20 myDir
-rw-r--r-- 1 code2care staff 0 Jun 5 17:19 sample.txt

As you can see the all the directories is denoted with a d and file has a - in instead. So you can use a command with grep to only filter those lines that starts with letter d using a regex '^d.*'
code2care@mac ~ % ls -l | grep '^d.*'
drwxr-xr-x 7 code2care staff 224 May 13 19:46 AndroidStudioProjects
drwx------@ 3 code2care staff 96 Feb 13 16:04 Applications
drwxr-xr-x 4 code2care staff 128 Jan 17 16:16 ClassRoom
drwx------@ 10 code2care staff 320 Jun 26 17:30 Desktop
drwx------@ 13 code2care staff 416 Jun 5 17:11 Documents
drwx------+ 36 code2care staff 1152 Jun 26 12:56 Downloads
drwxr-xr-x 9 code2care staff 288 Apr 24 17:11 IdeaProjects
drwx------@ 76 code2care staff 2432 Apr 13 16:39 Library
drwx------ 6 code2care staff 192 Mar 20 16:54 Movies
drwx------+ 7 code2care staff 224 Mar 13 22:42 Music
drwx------+ 4 code2care staff 128 Jan 2 23:28 Pictures
drwxr-xr-x+ 4 code2care staff 128 Jan 2 23:03 Public
drwxr-xr-x 6 code2care staff 192 Jun 5 15:03 PycharmProjects
drwxr-xr-x 4 code2care staff 128 May 15 12:22 eclipse
drwxr-xr-x 4 code2care staff 128 May 15 13:07 eclipse-workspace
drwx------ 11 code2care staff 352 Apr 3 14:57 iCloud Drive (Archive)
drwxr-xr-x 2 code2care staff 64 Jun 5 17:20 myDir
As you can see in the above, now ls along with grep shows only directories.
Now we need to do one more thing, make use of wc command to get the word count.
code2care@mac ~ % ls -l | grep '^d.*' | wc -l
17
Output:

βοΈThese commands would work on macOS, Linux and Unix Operating systems and Bash for Windows.
Have Questions? Post them here!
- Merge multiple zip files without unzipping (extracting)
- BSNL Broadband upgrades speed to minimum 2MBps for all users 512Kbps 1Mbps
- Static IP MTNL available at Rs. 200 per month
- Gmail Unable to upload because it is a folder or a package (like an application bundle or RTFD document)
- How to rerun last command in Zsh shell
- [Error] There was an error connecting to the apple id server
- Command to get count of only directories [macOS/Linux/Unix]
- Turn off Focus Mode on Mac
- Fix NVIDIA GeForce Experience ERROR CODE 0x0003
- How to submit website to dmoz directory
- How to stop or quit cat command?
- How to display only IP address using Terminal command
- Command: How to scp a file to remote server location?
- How to add Widgets to MacBook Desktop
- [IRCTC] Indian railways official eRail API 1.1 for developers to get train info
- [Fix] Steam: Friends Network Unreachable Error
- How to replace   with space
- How to change font, apply bold or italic styles, font size in Windows Notepad
- SQL: Check if table exists
- How to identify the version of IntelliJ
- How to fix: Please check your network connection (Retry)
- Top 10 emerging breakthrough trending technologies
- 100+ SEO Tips to improve your website search ranking
- How to enable line numbers in IntelliJ
- How to write hello world different languages syntax
- INSTALL_FAILED_INSUFFICIENT_STORAGE Error Android Emulator - Android
- Error:The SDK Build Tools revision (XX.X.X) is too low for project. Minimum required is XX.X.X - Android
- How to start/boot macOS in safe mode - Big Sur 11.0, Catalina 10.15, or Mojave 10.14 - MacOS
- Page actions are temporarily disabled [Google Search Console Page Crawling] - Google
- Android : How to make TextView Scrollable - Android
- How to check RAM details on Mac? - MacOS
- Access Windows share folder in Ubuntu Device in Network - Ubuntu
- Error running 'app': No target device found. - Android-Studio