language: en kae3g ← back to index
(unlisted) — This essay is not shown on the main index but remains accessible via direct link

kae3g 9590: The Filesystem - Hierarchical Organization

Phase 1: Foundations & Philosophy | Week 3 | Reading Time: 16 minutes

What You'll Learn

Prerequisites

The Persistent Garden

Memory (Essay 9580): Temporary, fast, expensive (like water - flows and evaporates)

Filesystem: Permanent, slower, cheaper (like seeds - stored for years)

Plant lens: "Filesystem is the seed bank—organized storage for knowledge that survives winter (power loss)."

Key difference: RAM is erased when power off. Filesystem persists.

Hierarchical Organization

Filesystems are trees (hierarchical, like organizational charts):

/  (root - top of tree)
├── home/
│   ├── alice/
│   │   ├── documents/
│   │   │   └── essay.md
│   │   └── projects/
│   └── bob/
├── etc/
│   ├── ssh/
│   │   └── sshd_config
│   └── nginx/
└── usr/
    └── bin/
        ├── python3
        └── clojure

Every item is either:

Paths describe location:

Plant lens: "Directories are branches, files are fruits/seeds, paths are routes through the garden."

Inodes: The Hidden Identity

What you see:

ls -l
# -rw-r--r--  1 alice  staff  1024 Oct 10 12:00 essay.md

What the filesystem sees:

Inode 12345:
  - Type: regular file
  - Permissions: rw-r--r--
  - Owner: alice (UID 501)
  - Size: 1024 bytes
  - Timestamps: created, modified, accessed
  - Data blocks: [block 8000, block 8001]
  - Link count: 1

The filename (essay.md) is just a pointer to the inode!

Inode = File's identity (metadata + data location)

Directory entry = Name → Inode mapping

Why This Matters

Multiple names, one file (hard links):

# Create file
echo "Hello" > original.txt

# Create hard link (another name for same inode)
ln original.txt backup.txt

# Both point to SAME inode!
ls -li
# 12345 -rw-r--r-- 2 alice original.txt
# 12345 -rw-r--r-- 2 alice backup.txt
# (Same inode number: 12345)

# Edit one:
echo "World" >> original.txt

# Other reflects change (same file!)
cat backup.txt
# Output: Hello
#         World

Plant lens: "Inode is the plant's DNA, filenames are labels we put on it."

Hard Links vs Soft Links (Symlinks)

Hard Links

Points to inode directly:

ln original.txt hardlink.txt

# If you delete original.txt:
rm original.txt

# hardlink.txt still works! (inode still exists)
cat hardlink.txt
# Output: (file contents)

Limitation: Can't link across filesystems (inodes are per-filesystem).

Soft Links (Symlinks)

Points to filename (like a shortcut):

ln -s original.txt symlink.txt

# If you delete original.txt:
rm original.txt

# symlink.txt breaks! (points to non-existent file)
cat symlink.txt
# Error: No such file or directory

Benefit: Can link across filesystems, can link to directories.

Comparison:

Hard LinkSoft Link
Points to inodePoints to filename
Survives file deletionBreaks if target deleted
Same filesystem onlyCross-filesystem OK
Can't link directoriesCan link directories

Plant lens:

The Unix Filesystem Hierarchy

Standard layout (Filesystem Hierarchy Standard - FHS):

/              Root (top of tree)
├── bin/       Essential binaries (ls, cat, sh)
├── boot/      Boot loader files (kernel)
├── dev/       Device files (hard drives, terminals)
├── etc/       Configuration files (system-wide)
├── home/      User home directories
├── lib/       Shared libraries (like .dll on Windows)
├── opt/       Optional software packages
├── proc/      Virtual filesystem (process info)
├── root/      Root user's home
├── tmp/       Temporary files (cleared on reboot)
├── usr/       User programs and data
│   ├── bin/   User binaries
│   ├── lib/   User libraries
│   └── share/ Shared data (docs, man pages)
└── var/       Variable data (logs, databases, caches)

Key directories:

/etc/: Configuration as text files

ls /etc/
# hosts, ssh/, nginx/, fstab, passwd, ...

/home/: Your files

ls /home/alice/
# documents/, downloads/, .config/, ...

/var/log/: System logs

tail /var/log/system.log
# See what's happening on your system

"Everything is a File"

Unix philosophy: Treat everything uniformly.

Not just regular files, but:

Device Files (/dev/)

# Hard drive
ls -l /dev/sda
# brw-rw---- 1 root disk 8, 0 Oct 10 12:00 /dev/sda

# Terminal
ls -l /dev/tty
# crw-rw-rw- 1 root tty 5, 0 Oct 10 12:00 /dev/tty

# Random number generator
cat /dev/urandom | head -c 10 | xxd
# Generates random bytes!

Interact with hardware as if it's a file (read/write).

Process Info (/proc/)

# Process 1234's info
cat /proc/1234/status
# Shows: memory usage, state, etc.

# CPU info
cat /proc/cpuinfo

# Memory info
cat /proc/meminfo

Virtual filesystem: Kernel generates content on-the-fly (not real files on disk).

Pipes (FIFOs)

# Create named pipe
mkfifo mypipe

# In one terminal:
cat mypipe

# In another terminal:
echo "Hello through pipe!" > mypipe

# First terminal shows: Hello through pipe!

Looks like a file, acts like a pipe (Essay 9550 - command line).

Filesystem Operations

Create

# File
touch newfile.txt
# Or:
echo "content" > newfile.txt

# Directory
mkdir newdir

# Nested directories
mkdir -p path/to/nested/dir

Read

# Entire file
cat file.txt

# First 10 lines
head -10 file.txt

# Last 10 lines
tail -10 file.txt

# Follow file (for logs)
tail -f /var/log/system.log

Update

# Append
echo "more" >> file.txt

# Overwrite
echo "new content" > file.txt

# Edit interactively
vim file.txt

Delete

# File
rm file.txt

# Directory (empty)
rmdir emptydir/

# Directory (with contents)
rm -r fulldir/

# Be careful! No undo!

Filesystem Metadata

Every file/directory has metadata:

stat essay.md

# Output:
#   File: essay.md
#   Size: 1024        Blocks: 8          IO Block: 4096
#   Device: 8,1       Inode: 12345       Links: 1
#   Access: (0644/-rw-r--r--)  Uid: (501/alice)   Gid: (20/staff)
#   Access: 2025-10-10 12:00:00
#   Modify: 2025-10-10 12:00:00
#   Change: 2025-10-10 12:00:00

Key metadata:

The House of Wisdom Parallel

Islamic scholars (Essay 9505) organized manuscripts in the House of Wisdom:

Their system:

House of Wisdom (Baghdad, 800-1200 CE)
├── Translation wing/
│   ├── Greek manuscripts/
│   ├── Persian manuscripts/
│   └── Indian manuscripts/
├── Mathematics section/
├── Medicine section/
├── Astronomy section/
└── Philosophy section/

Hierarchical organization (like filesystem!)

Librarians maintained:

Same principles:

Modern filesystem = Digital library catalog at massive scale!

Try This

Exercise 1: Explore Your Filesystem

# Where am I?
pwd
# Output: /home/alice

# What's here?
ls -la

# What's in parent?
ls ../

# Navigate
cd /etc
ls

# Back home
cd ~

Observe: Hierarchical structure (directories contain directories).

Exercise 2: Inode Investigation

# Create file
echo "Test" > file1.txt

# Check inode
ls -li file1.txt
# Output: 12345 -rw-r--r-- 1 alice file1.txt

# Create hard link
ln file1.txt file2.txt

# Check inode (same!)
ls -li file*.txt
# Output: 12345 -rw-r--r-- 2 alice file1.txt
#         12345 -rw-r--r-- 2 alice file2.txt

# Create symlink
ln -s file1.txt file3.txt

# Check inode (different!)
ls -li file*.txt
# Output: 12345 -rw-r--r-- 2 alice file1.txt
#         12345 -rw-r--r-- 2 alice file2.txt
#         67890 lrwxrwxrwx 1 alice file3.txt -> file1.txt

Observe: Hard links share inode, symlinks have own inode.

Exercise 3: "Everything is a File"

# Read from device
head -c 10 /dev/urandom | xxd
# Random bytes!

# Process info
cat /proc/cpuinfo | head -10

# Write to log (if you have permission)
echo "Test message" | sudo tee -a /var/log/test.log

Observe: Devices, processes, logs all accessible as files.

Going Deeper

Related Essays

External Resources

Reflection Questions

  1. Why hierarchical? (Why not flat? What about tags/labels instead of directories?)
  2. Is the FHS optimal? (Why /usr/bin vs /bin? Historical reasons or good design?)
  3. Should everything be a file? (Unix says yes. Windows uses more abstractions. Who's right?)
  4. What if filesystems were immutable? (Nix store is append-only! What if ALL filesystems were?)
  5. How would you organize 10 million files? (Hierarchical structure helps, but at what depth?)

Summary

Filesystems provide:

Key Concepts:

Unix Filesystem Hierarchy:

"Everything is a File":

Key Insights:

Historical Parallel:

In the Valley:

Plant lens: "Filesystem is the organized seed bank—hierarchical storage with metadata, preserving knowledge through winters (power cycles)."

Next: We'll explore permissions—who can read, write, and execute files. The security model that keeps your seeds safe from unauthorized access!

Navigation:
← Previous: 9580 (memory management) | Phase 1 Index | Next: 9592 (permissions who can do what)

Metadata:

Copyright © 2025 kae3g | Dual-licensed under Apache-2.0 / MIT
Competitive technology in service of clarity and beauty


← back to index