Nepedia
Back to Discover
Advanced Reader
💻

Directory (computing)

technology Maturity 7-9 Next article →

A directory is a vital cataloging structure used by computer file systems. It contains references to other computer files and can also contain other directories.

Files11 directory hierarchy
Files11 directory hierarchy

This structure allows a computer to organize vast amounts of data efficiently. Without directories, finding a specific piece of information would be extremely difficult. The name comes from real-world examples like a telephone directory. Just as a phone book lists names and numbers, a directory lists files and their locations.

Most modern computers use a hierarchical file system to manage data. This system is organized like a tree structure. In this model, a directory contained inside another directory is called a subdirectory. The relationship between these two is often described using biological terms. The containing directory is called the parent, while the contained directory is the child.

Files11 directory hierarchy
Files11 directory hierarchy

At the very top of this entire structure sits the root directory. The root directory is unique because it does not have a parent of its own. A reference to a specific location within this hierarchy is known as a path.

Directories can be understood through different metaphors depending on how you interact with them. In a graphical user interface, users often see directories as "folders." This visual metaphor uses icons that look like physical office folders.

However, there is a technical difference between the two. A directory is a fundamental file system concept. A folder is a graphical representation used to make that concept easier for humans to navigate. Some systems even use "smart folders," which are virtual and reflect the results of a search rather than a physical location in the hierarchy.

History shows how these organizational concepts have evolved over time. The folder metaphor was used as early as 1958. It appeared in the design for the Electronic Recording Machine, Accounting (ERMA) Mark 1. Later, the Xerox Star system also utilized this folder concept.

In early versions of the Unix operating system, the root directory served as the home directory for the root user. Modern Unix systems have changed this, usually using a different directory for that specific purpose. In Unix philosophy, the system actually treats directories as a special type of file.

To make file access faster, operating systems use a mechanism called a lookup cache. This process stores information in the computer's RAM, which is much faster than searching the entire disk.

Files11 directory hierarchy
Files11 directory hierarchy

In Unix-like systems, this is often called the directory name lookup cache, or DNLC. The cache stores mappings between path components, such as "/usr/bin," and their corresponding directory objects. By using fast structures like hash tables or radix trees, the system can bypass a full traversal of the file hierarchy. This dramatically improves performance for tasks that involve heavy metadata operations.

Different operating systems implement these caching and directory methods uniquely. The Linux kernel uses a structure called the dcache within its Virtual File System layer.

Dir command in Windows Command Prompt
Dir command in Windows Command Prompt

Each dentry in the dcache links to an inode and can represent a file or a subdirectory. These entries are stored in memory as long as there is no memory pressure. Other systems like macOS integrate lookup caching into their VFS layer. BSD variants, such as FreeBSD and OpenBSD, also implement their own directory lookup caches. Windows uses internal path caching within its NTFS and kernel object manager layers.

Managing directories becomes more complex in distributed file systems, such as NFS or AFS. In these systems, the cache must remain "coherent" across many different clients. This means that if one user changes a file, the change must be reflected in the caches of all other users.

Files11 directory hierarchy
Files11 directory hierarchy

To prevent errors or data loss, these systems use mechanisms like attribute timeouts or lease-based locking. If the system fails to maintain this coherence, it can result in stale metadata or incorrect path resolution. Properly optimized caches can lead to massive performance gains. In some benchmarks, they have shown orders-of-magnitude improvements in system boot times and file access speeds.

657 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (2)
File:Dir command in Windows Command Prompt.png
Dir command in Windows Command Prompt.png
File:Files11_directory_hierarchy.svg
Files11_directory_hierarchy.svg
More to explore

🔬 Go deeper

More advanced topics to explore

🪜 Step back

Simpler topics to build understanding

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.