Counting number of files in a directory with an OSX terminal command


I’m looking for a specific directory file count that returns a number. I would type it into the terminal and it can give me the specified directory’s file count.

I’ve already tried echo find "'directory' | wc -l" but that didn’t work, any ideas?


You seem to have the right idea. I’d use -type f to find only files:

$ find some_directory -type f | wc -l

If you only want files directly under this directory and not to search recursively through subdirectories, you could add the -maxdepth flag:

$ find some_directory -maxdepth 1 -type f | wc -l

Answered By – Mureinik

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published