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.
Asked
Active
Viewed 3.3k times
8
Gilles 'SO- stop being evil'
- 807,993
- 194
- 1,674
- 2,175
Dhiwakar Ravikumar
- 311
- 2
- 6
- 12
-
1@HaukeLaging That question is not the same, note "I'd like it to count **recursively**..." – goldilocks Nov 18 '14 at 10:19
2 Answers
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,055
- 7
- 87
- 112
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нιη
- 40,939
- 15
- 71
- 114