System Administration Guide
Chapter 2, Administering filesystems

Monitoring and limiting directory sizes

Monitoring and limiting directory sizes

To improve performance, limit the number of files and the filename length in critical directories. Limit working directories, such as login directories, to 62 files (plus the required ``.'' and ``..'' entries). A directory that contains fewer than 62 files fits in a single disk block and can be searched very efficiently. Data storage directories, such as spool directories, can contain up to 638 entries and still be viable.

NOTE: These directory size figures apply to filenames of 14 characters or fewer. As filename lengths increase (up to a maximum of 255 characters for most filesystem types), the number of files that fit on a single disk block decreases, thus reducing the maximum number of files in a directory.

To determine if a directory is too large, enter:

l . | wc -l

This command gives you the number of files in the directory listing. If this number is greater than 62 (for a working directory) or 638 (for a spool directory), the number of files in the directory might be affecting system performance.

To enhance performance, create a hierarchy of subdirectories with 5 to 10 directories at each level, then store the files in these subdirectories. Educate users to keep their login directories small by setting up a simple, clear hierarchy of subdirectories.

Even if you delete files so that you have fewer than 62 (or 638), the directory might still be oversized and inefficient. The directory remains the same size because empty directory slots are left when you move or remove files. Thus, if large numbers of files are moved in and out of a directory (as in the case of a spool directory), the directory can remain very large even if there are very few files in the directory.

You can reduce the size of the directory by reducing the number of empty directory slots.