I use this one, few examples: ls -Ap directory01/directory02 | grep -v /$ | wc -l ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l It works like this: * `-p` with `ls` adds `/` at the end of the directory names. * `-A` with `ls` lists all the files and directories, **including** hidden files but **excluding** `.` and `..` directories. * `grep -v /$` only shows the lines that **do not** match (`-v` option) lines that end with `/`. (directories) * `wc -l` counts the number of lines. Either I use for example mix of these: ls -Ap directory01/directory02 | grep -v /$ | wc -l ; / ls -Ap directory01/directory02/exampl* | grep -v /$ | wc -l; / ls -Ap /home/directory01/directory02 | grep -v /$ | wc -l So, for example from the: $ tree . ├── directory01 │ ├── directory02 │ ├── directory03 │ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png │ └── directory04 I will get count $ ls -Ap directory01/directory03 | grep -v /$ | wc -l 2 It will be counted both │ ├── Screenshot from 2022-04-19 15-12-55.png │ └── Screenshot from 2022-04-19 16-05-05.png but no directory04