Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Wondering if there is a limit to the number of files that can be stored inside a directory, in CentOS 6. There is one particular directory which could potentially have millions of subdirectories.

Storage capacity aside, is there a limit to the number of files that can be contained in a directory? (I assume here that "file" can mean either a file or a directory).

Thanks very much!

share|improve this question

marked as duplicate by mdpc, Bryan, Ward, Jim B, Dennis Kaarsemaker May 10 '13 at 16:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
I believe that there is an excellent wikipedia article comparing the filesystems and items like this. –  mdpc May 9 '13 at 18:45
1  
@Bryan: This is not a good duplicate, because the only answer in the linked question are Wikipedia links, which is not a good kind of answer on Server Fault. –  Sven May 9 '13 at 21:11
    
@Svw, maybe not a good duplicate, but it's still a duplicate. You could always improve the answer to the other question by adding information from the linked wiki page if you think that it will improve it. –  Bryan May 10 '13 at 20:04

3 Answers 3

up vote 10 down vote accepted

It depends on your filesystem. I'm going to assume it's ext4:

The maximum number of files is global, not per directory, and it's determined by the number of inodes allocated when the filesystem was created. Try running the following command to see the number of inodes per filesystem.

    $ df -i
    Filesystem       Inodes  IUsed    IFree IUse% Mounted on
    /dev/sdb2       7864320 388119  7476201    5% /

The maximum number of subdirectories seems to be 64000 according to here (http://en.wikipedia.org/wiki/Ext4), but see also (http://kernelnewbies.org/Ext4) -- suggests that it is unlimited.

share|improve this answer
    
Thanks a lot! Will check into this. –  Juan Carlos Coto May 9 '13 at 19:41

It depends on the file system. ext3 suppport ~32000 subdirectories (not files!) in a given directory, with ext4 it's 64000 by default. xfs has no limit to my knowledge.

share|improve this answer
    
Thanks very much! –  Juan Carlos Coto May 9 '13 at 19:40

I'd like add to the already correct answers that you should consider not putting too many files in a single directory. Most software doesn't handle that well (e.g. mc will be slow, many gui tools will be unusable). It's better to create a hierarchy of nested folders and distribute the files in them using some algorithm (hash of file name or content or any other method which will distribute the files equally). That's what many mature programs (e.g. squid) do.

share|improve this answer
    
Excellent. Good suggestion, thanks! –  Juan Carlos Coto May 9 '13 at 21:00

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