If you need to count the number of files in a directory as well as all the files in its subdirectories then use the below command.
Count Number of Files in Current Directory
Use the find . -type f | wc -l command to count the number of files in the current directory.
[root@dbappweb ~]# find . -type f | wc -l 4654069
You can also count the number of subdirectories under a directory by using the find . -type d | wc -l command.
[root@dbappweb upload]# find . -type d | wc -l 1853079
Count Number of Files in Any Directory
Use the below command to count the number of files in any directory. /upload is the path of the directory.
[root@dbappweb upload]# find /upload -type f | wc -l 4654075
You can also count the number of subdirectories under a directory by using the find /upload -type d | wc -l command.
[root@dbappweb upload]# find /upload -type d | wc -l 1853079
Last Updated: Apr 11, 2018