Is 500,000 files in my home directory too much

On my mac I did find ~/ in the terminal to list all the files in my home directory it listed over 500,000. This seems like an awful lot to me and occasionally my computer is slow. Is there any recommended maximum number of files to have? Even though a lot of the files are little would they cause the file system index to get really large and unwieldy?


Solution 1:

As pointed out in a comment, you're using a command that is locating files within directories below the directory in question. While you may only be able to count to about 20 (fingers and toes) OS's are much much better at dealing with large numbers of files, and this is really an issue you shouldn't worry about.

Now if your computer is slow, you might want to look into what is using memory.

Solution 2:

If a directory grows larger than the directory cache, access to it would indeed be slowed down significantly. A users home directory is one of the directories that gets traversed often, especially since many programs started by and for the user start with it as their working directory.

This definitely is a reason to keep the home directory itself organized, and shift clutter into subdirectories.

As Ian pointed out in his comment, your home directory may be perfectly organized though - all you have been looking at is the collated number of files and directories contained within the structure of your home directory, no matter how deep.

To find out how many entries your home directory is containing directly, you can use find restricted by depth:

find $HOME -depth 1 |wc -l

To anyone wanting to circumvent the snags of a less-than-optimal directory structure, the 2015 article by Tsai et al., How to get more value from your file system directory cache would probably be one of the easier introductions to the subject.