This post will show you how to count files under a Linux directory.
Step 1: cd to the folder you would like to count the files.
Step 2: issue the following command, then you should see a number, which is the number count of the files under the current directory.
find . -type f | wc -l
-type findicates counting files only. You can remove the-type fto include directories (and symlinks) while counting.|(note: not¦) redirectsfindcommand’s standard output towccommand’s standard input.wc(stands for word count) counts newlines, words, and bytes on its input (see here for more details.).-lto count just newlines.
Notes:
- This command may overcount if filenames can contain newline characters.
For more commonly used Linux commands, check my other posts at here and here .