Counting files in a Linux directory

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 f indicates  counting files only.   You can remove the -type f to include directories (and symlinks) while counting.
  • | (note: not ¦) redirects find command’s standard output to wc command’s standard input.
  • wc (stands for word count) counts newlines, words, and bytes on its input (see here for more details.).
  • -l to 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 .

Leave a Reply

Your email address will not be published.