8

In windows you get a count of the number of subdirectories within a directory.Is there any equivalent on Linux ? I'd like it to count recursively & Not stop at a single level.

2 Answers2

9

Use find to count all directories in a tree starting from current directory:

find . -mindepth 1 -type d | wc -l

Note, that -mindepth is required to exclude current directory from the count.

You can also limit depth of search with -maxdepth option like this:

find . -mindepth 1 -maxdepth 1 -type d | wc -l

More find options are available. You can check man page for that,

rush
  • 27,403
1

If you want to get number of directories and files use this:

tree /path/to/given/dir | awk 'END{print}'

If you want only number of directories, add -d option:

tree /path/to/given/dir -d | awk 'END{print}'

tree works recursively.

αғsнιη
  • 41,407