Recursively count all files in a directory from the terminal

March 12, 2015

If you utilize the terminal on a regular daily basis like I do you are bound to run into times when you need to get a count of how many files exist in a directory structure. Here is some code that will display that count for you.

find . -type f | wc -l

The ‘.’ in the command above refers to the current directory. If the directory you are inspecting exists elsewhere replace ‘.’ with the path to that directory.