Labs ICT
Pro Login

Directory Structure

Single-level, two-level, tree, and acyclic graph directories.

Organizing Files Hierarchically

Without directories, every file on your computer would be in one flat list — imagine having 50,000 files all sitting at the root level with no organization. Directories solve this by allowing you to group files into nested folders, creating a tree-like structure.

The directory structure is one of the most important organizational tools in computing. It's how you keep your work documents separate from your music, your system files separate from your applications, and your project files organized by client or topic.

Single-Level Directory

The simplest approach: all files are stored in one directory. Every file has a unique name. This works for very simple systems (like early embedded devices) but doesn't scale.

The problem is obvious: with thousands of files, finding anything becomes a nightmare. File names must be unique across the entire system, limiting your naming options. You can't have two files named "report.txt" anywhere on the disk.

Two-Level Directory

A two-level directory adds a user directory above the file directory. Each user gets their own directory, and within it, they can have their own files. User A can have "report.txt" and User B can also have "report.txt" — no conflict because they're in different user directories.

This is better, but still limiting. You can only organize by user, not by project, topic, or any other criteria.

Tree Directory Structure

The tree directory is what modern operating systems use. Directories can contain files and other directories, creating a hierarchical tree. The root directory (/ or C:\) is at the top, and everything branches down from there.

Paths describe the location of a file in the tree:

  • Absolute path — Starts from the root: /home/user/documents/report.txt
  • Relative path — Starts from the current directory: documents/report.txt

The tree structure gives you unlimited organizational flexibility. You can create folders within folders within folders, organizing your files exactly the way that makes sense for your workflow.


  Tree Directory Structure:

                        /
                        │
        ┌───────┬───────┼───────┬───────┐
        │       │       │       │       │
      home    etc     var     usr     tmp
        │       │       │       │
        │    ┌──┴──┐    │    ┌──┴──┐
      alice  │     │    │    │     │
        │   ssh  nginx  │   bin  lib
   ┌────┴────┐          │
   │         │          │
   documents photos     log
   │    │      │        │
   │    │    vacation   syslog
   report  notes.jpg
  .txt

Paths describe the location of a file in the tree:

  • Absolute path — Starts from the root: /home/alice/documents/report.txt
  • Relative path — Starts from the current directory: documents/report.txt

Acyclic Graph Directories

An acyclic graph allows directories to share files through links. A file can exist in multiple directories simultaneously — it's the same file, not a copy. This is useful when multiple projects need access to the same file.

There are two types of links:

  • Hard links — Multiple directory entries point to the same inode (file metadata). The file exists until the last hard link is removed.
  • Symbolic links (soft links) — A special file that contains the path to another file. If the original file is deleted, the symbolic link breaks.

The constraint is that the graph must be acyclic — no circular links. If directory A points to directory B, and B points back to A, you'd create an infinite loop. File systems prevent this to avoid confusion and corruption.

Path Resolution

When you access a file using a path, the OS performs path resolution — it starts at the root directory and follows each component of the path until it reaches the target file. Each directory in the path contains entries that point to the next directory or the final file.

This is why file access takes time — the more directories deep a file is, the more lookups are needed. File systems cache frequently accessed directory entries to speed up this process.