Count the Number of Files in a Directory

ls -l | wc -l
  • ls: list directory contents
    • -l: list in long format
  • wc: word, line, character, and byte count
    • -l: the number of lines is written to the standard output

This command counts the number of listed lines. I find this most useful when I want to quickly see how many logs or records have been generated by a process.

Nicholas Nadeau, Ph.D., P.Eng.
Nicholas Nadeau, Ph.D., P.Eng.
Project Director

Nicholas Nadeau is the project director at Halodi Robotics, leading their mission of bringing safe and capable humanoid robots to everyone.

Related