LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Maximum number of files per folder (https://www.linuxquestions.org/questions/linux-general-1/maximum-number-of-files-per-folder-877599/)

alaios 04-28-2011 07:23 AM

Maximum number of files per folder
 
Dear all,
I would like to ask you if there is any maximum allowed number of files per folder in linux (without risking it to lose everything).
I am using openuse 11.4 with latest kde (4.6?).

I am trying something fast and dirty and it might be that one folder will contain like 10^6 files.

Is there is anything I should be warned about that?

Best Regards
Alex

druuna 04-28-2011 09:00 AM

Hi,

I don't think there is a maximum number of files per directory, the maximum amount of files depends on the file-system used. Have a look here: Of filesystems and partitions

Depending on the FS there is a maximum amount of sub-directories you can create in one directory (31998 for ext3 for example).

If one million or more files in a directory is workable is another question, you might run into other (command) limits. For example: rm * might not work (argument list too long).

Hope this helps.

wpeckham 04-28-2011 03:16 PM

File and directotry limits
 
To be more precise, since we stopped using the old POSIX standard: OS limits on the number of files in a directory, the number of directories, or the size of files is irrelevant. The real restriction if from the File System limits. In some cases those are tunable to achieve different numbers, but the defaults are published.

Most of the limits would currently require someone do something VERY STUPID to approach on a small or home system. Personally, I cannot afford enough storage to even come close.


If you have more detailed questions you can post them here, but you may find the information faster through google using the key "FILE SYSTEM LIMITS and the name of your file system. (EXT4, EXT3, EXT2, JFS, XFS, REISERFS, etc)

jefro 04-28-2011 04:38 PM

I have always assumed a number of limits. Files per folder seemed to be one of them in all file systems but may be actually sub directories and files are considered the same.

As for ext3

^ The maximum number of inodes (and hence the maximum number of files and directories) is set when the file system is created. If V is the volume size in bytes, then the default number of inodes is given by V/213 (or the number of blocks, whichever is less), and the minimum by V/223. The default was deemed sufficient for most applications. The max number of subdirectories in one directory is fixed to 32000.

punitsolanki 05-01-2011 02:07 AM

Hi,

Yes there is a limit but not as per files its as per filesystem or partiion , its 4 TB for ext4 filesystem.

Punit

druuna 05-01-2011 02:56 AM

Hi,
Quote:

Originally Posted by punitsolanki (Post 4342525)
Yes there is a limit but not as per files its as per filesystem or partiion , its 4 TB for ext4 filesystem.

You seem to have mixed size and amount for ext4:

- Max file size: 16 TiB
- Max number of files: 4 billion


But...... that was _not_ the question the OP asked. Maximum number of files per folder. Which has already been answered.

smeezekitty 05-01-2011 03:26 PM

Quote:

Originally Posted by jefro (Post 4339887)
I have always assumed a number of limits. Files per folder seemed to be one of them in all file systems but may be actually sub directories and files are considered the same.

As for ext3

^ The maximum number of inodes (and hence the maximum number of files and directories) is set when the file system is created. If V is the volume size in bytes, then the default number of inodes is given by V/213 (or the number of blocks, whichever is less), and the minimum by V/223. The default was deemed sufficient for most applications. The max number of subdirectories in one directory is fixed to 32000.

32000? Are you sure its not 32767 (0x7FFF)?

druuna 05-01-2011 03:33 PM

Hi,

The correct number is 31998 (ext3, max sub-directories per one directory).

From Ext3 (wiki):
Quote:

There is a limit of 31998 sub-directories per one directory, stemming from its limit of 32000 links per inode.
The other 2? A directory starts with a link count of 2.

jefro 05-01-2011 05:38 PM

Dot and dot dot?

punitsolanki 05-01-2011 11:08 PM

oh koool Thanks druuna

druuna 05-02-2011 03:48 AM

Hi,
Quote:

Originally Posted by jefro (Post 4343194)
Dot and dot dot?

Dot, yes. Dot dot, no.

Any object in the file system must have a directory entry that connects it into the file system. For example, if you have a directory like "/tmp", there's a pointer in the root directory ("/") that points to the "tmp" directory entry. So that gives you one link.

Every directory contains the "." link that points back to itself. So that gives us the minimum value of 2 links per directory.

Every subdirectory has a ".." link that points back to its parent, incrementing the link count on the parent directory by one for each subdirectory created.

The .. (dot dot) entry points to (and increases) its parent!
Code:

cd /
ls -la /tmp
drwxrwxrwt  5 root  root      4096 May  2 09:56 .
drwxr-xr-x 26 root  root      4096 May  2 10:42 ..

mkdir /Foo
ls -la /Foo /tmp
/Foo:
drwxr-xr-x  2 root root 4096 May  2 10:45 .
drwxr-xr-x 27 root root 4096 May  2 10:45 ..

/tmp:
drwxrwxrwt  5 root  root      4096 May  2 09:56 .
drwxr-xr-x 27 root  root      4096 May  2 10:45 ..

rm -rf /Foo

ls -la /tmp
drwxrwxrwt  5 root  root      4096 May  2 09:56 .
drwxr-xr-x 26 root  root      4096 May  2 10:46 ..

Hope this helps.


All times are GMT -5. The time now is 04:12 AM.