LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   Maximum number of files in a directory (https://www.linuxquestions.org/questions/general-10/maximum-number-of-files-in-a-directory-183643/)

neranjana 05-20-2004 06:08 AM

Maximum number of files in a directory
 
Hi

Can anybody tell me how many files could be created in one directory? I just need a rough figure. 10,000? 1,000,000? 1,000,000,000,?

Thanks

Neranjana

trickykid 05-20-2004 06:27 AM

I would think it depends on your hard drive space actually. Most configurations if your using Linux use 4k inodes. So each directory or file at minimum would take up 4k of space by default.

So lets make it easy, doing some simple math and hopefully I did it right as its way to early, if you had a 2 GB partition using 4k inode allocations, you could fit 500,000 files on the partition.

So your question I think is irrelevant to directories, it all depends on your drive itself, size of inodes and size of all the files, etc.

Lets just put it this way, too hard to determine, so if it was a multiple choice quiz question, I'd choose: "Not enough information provided to answer"

;)

dave_starsky 05-20-2004 07:00 AM

i'm sure you can have as many files as you want in a directory. A directory is merely a file which stores information about the other files which are "within" it.

SciYro 05-20-2004 05:22 PM

it also depends on the file system used, reiserfs can support a lot... others can only support a few ..

neranjana 05-20-2004 09:36 PM

This is a question to trickykid.

Suppose I have ext3 and I have 80 GB partition. Suppose the size of the file is immaterial. (I would not run out of disk space.) But there are some problems. As you have mentioned, if it takes 4k to allocate a file then if I have say 100 files of the size of 10k then that would mean it would take 1MB for the files. Suppose this is not important. But the directory would take 4*100 k just to keep the info about the files, wouldn't it? I've heard that there is a limit of 4GB for a file in Linux. So it would mean that any directory could only be as big as 4GB (this is without the actual files inside it. Just the file names.) So it would mean that 4,000,000/4 would be the maximum number of files that a directory could keep inside it, wouldn't it?

Am I on track or am I way off the mark?

trickykid 05-20-2004 09:53 PM

Quote:

Originally posted by neranjana
This is a question to trickykid.

Suppose I have ext3 and I have 80 GB partition. Suppose the size of the file is immaterial. (I would not run out of disk space.) But there are some problems. As you have mentioned, if it takes 4k to allocate a file then if I have say 100 files of the size of 10k then that would mean it would take 1MB for the files. Suppose this is not important. But the directory would take 4*100 k just to keep the info about the files, wouldn't it? I've heard that there is a limit of 4GB for a file in Linux. So it would mean that any directory could only be as big as 4GB (this is without the actual files inside it. Just the file names.) So it would mean that 4,000,000/4 would be the maximum number of files that a directory could keep inside it, wouldn't it?

Am I on track or am I way off the mark?

No, you could have a directory with three 4gb files that reside in that one directory. Just cause a files reside in a directory doesn't mean that all the files are limited to 4gb in this case you explained, the filesystem doesn't work like that.. ;)

dave_starsky 05-21-2004 12:19 PM

The size of the files doesn't matter, the directory is a file which contains references to the files, so it just has to store the address for the file. (i think thats how it works anyway)

plus, everything is inside the / directory

Lazypete 04-14-2009 12:48 PM

Actually as trickykid said no, you can have 3 files of 4GB in the same dir. Its actually a physical limitation. 4GB is the maximum of a 32bit system, because the maximum number you can write is 2^32 = 4 294 967 296
so you can't say I would like to request bit number 5 000 000 000, that number can't be sent over a 32bit bus.

On a 64 bit system that barrier is lifted to a much higher value 2^64

There are two things you must consider when figuring the file system.
The space a file use, its data part, and the commonly forgotten aspect that this file also need adressing in the file allocation table.

There is usually a maximum number of file in a single directory, I know there is one in FAT16 and FAT32. I just dont know if there are in other filesystem.

Maybe the way ext2, ext3, ext4 or reiserfs are build there is no such limit.

sundialsvcs 04-14-2009 01:36 PM

Actually, what I would suggest doing is ... use a database, or databases. That's basically what you're doing anyway, but you're doing it the hard way. If you start running into the general vicinity of "a design limit," back off.

jiml8 04-16-2009 11:49 AM

I almost bit on this too, but I reviewed the thread, saw the dates, and said "this is a really moldy oldie".

ProtoformX 04-16-2009 10:46 PM

Quote:

Originally Posted by Lazypete (Post 3508635)
Actually as trickykid said no, you can have 3 files of 4GB in the same dir. Its actually a physical limitation. 4GB is the maximum of a 32bit system, because the maximum number you can write is 2^32 = 4 294 967 296
so you can't say I would like to request bit number 5 000 000 000, that number can't be sent over a 32bit bus.

On a 64 bit system that barrier is lifted to a much higher value 2^64

There are two things you must consider when figuring the file system.
The space a file use, its data part, and the commonly forgotten aspect that this file also need adressing in the file allocation table.

There is usually a maximum number of file in a single directory, I know there is one in FAT16 and FAT32. I just dont know if there are in other filesystem.

Maybe the way ext2, ext3, ext4 or reiserfs are build there is no such limit.

That would be wrong my friend, sorry to intrude but 32bit systems since the Pentium Pro are limited to 64gigs, PAE (Physical Address Extension) can extend the upper limit using 36bit addressing instead of 32.

Also this only applys to memory, not hard drive space, if that was the case everyone who didn't have 64bit systems would be limited to a 4096mb hard drive. Since this is not the case the amount of data on a harddrive is irreverent, even if it where, you could always limit the addressing to 32 or even 36bits and have a zillion bit addressing, it would be horribly slower, but can be done via look up table. See unreal mode programming, you basically enter 32bit addressing space save the memory table in the stack and return to 16bit real mode reload the stack and you are now using a 16bit mode with 32bit addressing...so now you have all the benefits of 32bit protected mode with the speed of 16bit real mode. but you can only access 64kb of memory at a time (not a huge deal for an assembly coder).

demerson3 09-30-2009 01:30 AM

JUST READ WIKIPEDIA! (read both ext2 and ext3, reiserfs, etc.)

All the answers are there!

There is a LOT of misinformation in this thread (e.g. 4 GB max file size -- not true)

Frustin 05-13-2010 03:09 AM

Quote:

Originally Posted by demerson3 (Post 3701426)
JUST READ WIKIPEDIA! (read both ext2 and ext3, reiserfs, etc.)

All the answers are there!

There is a LOT of misinformation in this thread (e.g. 4 GB max file size -- not true)

right, so tell us; using the information on wikipedia, how many?

smeezekitty 05-13-2010 12:00 PM

All of you act like wikipedia is so untrustworthy yet its so well maintained, i think you are more untrustworthy.

demerson3 05-13-2010 01:33 PM

Quote:

Originally Posted by Frustin (Post 3966710)
right, so tell us; using the information on wikipedia, how many?

Are you serious?

The maximum is 392,471,693. And five eighths. With a cherry on top.

/sarcasm

It's not so simple as that: the number is different for every partition, and is equivalent to the maximum number of inodes for that particular partition, which depends on the file system type, file system size, and block size. Most people will run out of drive space before they run out of inodes, so this is rarely an issue. If it's that important to you, go read wikipedia and figure it out for yourself. I'm not going to try and summarize what's there because you are too lazy to do some research. If you have an unusual use case where you might potentially run into the limit, then you'll need to understand what wikipedia says on the subject anyway.

You're a big boy, you can read and do math without my help.


All times are GMT -5. The time now is 06:56 AM.