K
K
Kirill Kirik2021-04-13 13:12:19
linux
Kirill Kirik, 2021-04-13 13:12:19

How to display the number of subdirectories in a directory?

Which command can display the number (number) of subdirectories in a directory?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander, 2021-04-13
@KoyaKoya

ls -d /path/to/directory/*/ | wc -l
/path/to/directory - directory
*/ - indication to browse inside the directory

V
vreitech, 2021-04-13
@fzfx

for example like this:

find /path/to/directory -maxdepth 1 -type d | wc -l

/path/to/directory - directory.

X
xotkot, 2021-04-13
@xotkot

exa -Da ПУТЬ | wc -l
exa as a replacement for ls

S
Saboteur, 2021-04-13
@saboteur_kiev

Here is a solution that works instantly, regardless of the number of directories:
echo $(( $(stat -c '%h' /path/to/directory) -2 ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question