Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to store 100k files (around 40GB) in a USB drive. Each file has a unique int id (e.g 45000).

Option one is to put all files in a single folder:


Option two is to create a [1-9][0-9]* folder hierarchy based on that id:


Which option will scale better? I can understand that the second option will require tons of folders but each folder will at most contain 10 folders and 1 file. Maintenance will not be an issue since everything will be controlled by an application.

Note that this is a USB drive on linux and based on the above I'd also like to know whether I should go with FAT32 or NTFS.

share|improve this question
FAT32 or NTFS? For preference, neither - JFFS2 is the best option for disk life, and ext4/reiser for read speed. – symcbean Dec 29 '10 at 17:06
Wouldn't it be just easier to empirically test the different scenarios instead of guessing? – Marcin Dec 29 '10 at 17:37
up vote 6 down vote accepted

I would recommend ext3/4 for use with Linux as my personal preference.

For the file structure I would recommend option number 3 (a balance of directory depth and files per directory). This is really just about choosing a tree data structure. To achieve this for the files I would do a md5sum hash of each file and use the first x characters of each file as directories. The characters will always be hexidecemial characters so each branch will be 16 directories wide. The number of characters you chose will be the height of the tree structure.

For example:

kbrandt@alpine:~/scrap$ md5sum

Would go in a something like ./0/3/b/

How to pre-create directories on linux for file storage? shows you how to precreate the directories.

This is a generic solution that works pretty well for many use cases and should create a pretty good distribution of files.

share|improve this answer

Some level of folder-tree system is definitely recommended; avoid putting more than about 10k files per folder. Don't use FAT if NTFS or EXT will work.

share|improve this answer
  • Ext2: Should use directories. Files are looked up by scanning through a list of entries.
  • Ext3: You can dump them all in the root directory. The HTree structure will make accessing them reasonably fast. I recommend this.
  • FAT32: I know less about this one, but given the history of directory entry limits, I would presume that it acts a lot like Ext2.
  • NTFS: Avoid with Linux unless you need compatibility with Windows. Uses B+ trees, which should be reasonably fast.

In cases where you are using a directory structure, I'd put 100-200 files in the directory. So, at the top level, perhaps this:

[0-99] #Directory entries
[0-99] #File entries

And below that...

[0-99] #Directory entries
[directory prefix][0-99] #File entries -- so in /37/76, one might find 377692 .pdf
share|improve this answer

FAT slows down as the number of files on the disk increases and not per directory, so you should not have any differences.

Read this M$ paper about FAT32

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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