Sunday, July 10, 2022

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

Issue

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?


Solution

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
Answer Checked By - Willingham (WPSolving Volunteer)