Count the Number of Files in a Directory

From the Linux command line a short command to count the number of files in a directory.

ls | wc -l

In the above command:

  • ls lists the files in the directory
  • “|” pipes the result through to the following command
  • wc -l performs a word count on what has been passed to it. In this case the number of lines (the -l parameter).

Other examples of the use of wc can be found using wc –help. And likewise further examples of the use of ls are found using ls –help.