20

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?

0

4 Answers 4

24

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.

12

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

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

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.:

a/aaron.dat
a/alex.dat
a/alan.dat
b/bill.dat
b/brian.dat

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

a/a/aaron.dat
a/l/alex.dat
a/l/alan.dat

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

2009-10-04/logfile-01.txt
2009-10-05/logfile-01.txt
2009-10-05/logfile-02.txt

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.

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .