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:
-pwithlsadds/at the end of the directory names.-Awithlslists all the files and directories, including hidden files but excluding.and..directories.grep -v /$only shows the lines that do not match (-voption) lines that end with/. (directories)wc -lcounts 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 [plain files]
$ 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 [not a plain file]
directory04