What's the maxium number of files a Unix folder can hold?
I think it will be the same as the number of files.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityWhat's the maxium number of files a Unix folder can hold?
I think it will be the same as the number of files.
On all current Unix filesystems a directory can hold a practically unlimited number of files. Whereas "unlimited" is limited by diskspace and inodes - whatever runs out first.
With older file system designs (ext2, UFS, HFS+) things tend to get slow if you have many files in a directory. Usually things start getting painful around 10,000 files. With newer filesystems (ReiserFS, XFS, ZFS, UFS2) you can have millions of files in a directory without seeing general performance bottlenecks.
But having so many files in a directory is not well tested and there are lots of tools which fail that. For example, periodic system maintenance scripts may barf on it.
I happily used a directory with several million files on UFS2 and had seen no problems until I wanted to delete the directory - that took several DAYS.
It depends how many inodes the filesystem was created with. Executing
df -i
will give you the number of free inodes. This is the practical limit of how many files a filesystem and hence a directory can hold.
I assume you are thinking of storing a lot of files in one place, no?
Most modern Unix files systems can put a lot of files in one directory, but operations like following paths, listing files, etc. involve a linear search through the list of files and get slow if the list grows too large.
I seem to recall hearing that a couple of thousand is too many for most practical uses. The typically solution is to break the grouping up. That is,
/some/path/to/dir/a/
/some/path/to/dir/b/
...
/some/path/to/dir/z/
and store your files in the appropriate sub-directory according to a hash of their basename
. Choose a convenient hash, the first character might do for simple cases.
Cristian Ciupitu writes in the comments that XFS, and possibly other very new file-systems, use log(N)
searchable structures to hold directory contents, so this constraint is greatly ameliorated.
ext3
one of the most common linux filesystem formats gets really sluggish if you have around 20k + file in a directory. Regardless of how many it can hold, you should try to avoid having that many files in one directory.
From the comment you left, I think you don't really care about how many files/folders your FS can host.
You should probably consider using ModRewrite and rewriting site.com/username to site.com/?user= or something of the kind and store all your data in a database. Creating one folder per user is generally not necessary (and not a good idea).
That said, each filesystem has limits, and df
can tell you how many inodes are available on each partition of your system.