Tool to find which MacOS folders have the largest number of files in them?

I’m looking for a tool that will tell me which folders on my Mac have the most files in them – the largest NUMBER of files, not the largest files by size. Anybody know of anything that will do that?

Ideally, I’d like to get a list – here are the folders with the largest number of files in them, in order by number of files, and how many files are in each.

This is to solve a problem I’m having with BackBlaze.

Anybody know of a utility or a command line that can answer this question for me?


To find the count of all files in a directory (and sub-directories) use

find . -type f | wc -l

The basic idea is to us wc to count. You could build off this to write a report listing each directory in the parent.

Note: gatekeeper prevents accessing system-level folders with this

1 Like

Thanks! I tried that in my Documents folder and the result returned a single number. Is there a way to get a list of folders and sub-folders, with the number of files in each folder, ranked from largest number of files to smallest?

What you’re asking for can, of course, be done, but it’s not trivial. It would require a script of a dozen or two lines of code, I believe.

1 Like

Open terminal, go to the folder you want to look at (cd Documents or whatever) and run:
find . -maxdepth 1 -type d -print0 | while read -d ‘’ -r dir; do num=$(find $dir -ls | wc -l); printf “%5d files in directory %s\n” “$num” “$dir”; done

Another solution in Python3:

import os
path = '/Users/you_user/Documents/' #insert your path
cutoff = 0 # cutoff parameter, will ignore folders with number of files less than n
for dir,subdir,files in os.walk(path):
    if len(files) > cutoff:
        print(dir, str(len(files)))
1 Like

Sorry, I don’t know why this didn’t occur to me earlier. HoudahSpot can do this. You can choose to have HoudahSpot display any attribute you wish in columns. Just click the column headers, choose “More Columns…” and pick the attribute you want displayed.

for example:

So then adjust your HoudahSpot search to ~\Documents (or any other root), for example:

Finally, sort the display by “Number of Items” – click twice to sort by descending order thus putting the largest count at the top.

I use omnidisksweeper from the omni group: Free app that should give you the information you need.

The poster wanted the number of files in a directory, not the size. OmniDisksweeper only reports size.

This seems to be working. And not slowing down my Mac any, which is kind of amazing.

So far so good!

Good deal.

HoudahSpot uses Spotlight data, and it should merely be reading that metadata cache so it’s not polling the entire machine. (Unlike OmniDisksweeper, which looks inside every folder every time it is launched.)

1 Like