Using Redhat, if that makes a difference.

Is there a default limit? Can it be changed? If not, are there any workarounds to increase the number of folders allowed in a directory?


It depends on what filesystem your distribution uses. If you use a newer desktop distribution (i.e. Ubuntu 9.10, a recent version of Fedora), you probably use ext4. If you use something older, it is most likely ext3.


In ext2, 32,768 according to Wikipedia - http://en.wikipedia.org/wiki/Ext2fs#File_system_limits. Depends on what file system you use.

  • 3
    Yep. Folder count is attached to the file system, not the OS. – Satanicpuppy Nov 5 '09 at 19:48
  • Looks like ext4 bumps that limit to a hard 64k but supports even more than that through tweaking – basszero Nov 5 '09 at 21:20

You may want to consider alternatives to whatever it is you're trying to do. Even if you stay under the filesystem limit (e.g., 32k for ext2), storing tens of thousands of files in a single directory can be cumbersome to say the least.

One possibility is that you're trying to use the filesystem for something that would be more suited to a database. Consider storing your data in a PostgreSQL, MySQL, or even a sqlite database. There aren't too many filesystems that cope well with a huge number of files-- moving or backing up your data will be slow.

If you really need to store lots of files, consider alternative directory structures. For example, you may be able to separate your files alphabetically, e.g.:


This approach can scale by increasing the depth of your separation, e.g.,:


Or if you are entering daily log files or receiving daily deliveries, you could separate them by date, e.g.:


In this particular case, you would probably also want to cron a job to package old logs into zipped tarballs to reduce the file count.


Folder limits are why enterprise systems which have to deal with an arbitrary number of files will store in one or two subdirectories based on a hash of the filename. For example, md5() the filename, and use the first four bytes as a subfolder to store the file in; for additional levels, use the next 4 for an additional subfolder, or the next 4 after that, etc. Most systems would never exceed 2 levels deep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.