kae3g 9590: The Filesystem - Hierarchical Organization
Phase 1: Foundations & Philosophy | Week 3 | Reading Time: 16 minutes
What You'll Learn
- How filesystems organize data hierarchically (directories, files, paths)
- Inodes: The hidden identity system behind files
- Hard links vs soft links (symlinks)
- The Unix filesystem hierarchy (/, /home, /etc, /usr, /var)
- Why "everything is a file" in Unix
- Filesystem operations (create, read, update, delete)
- How the House of Wisdom organized manuscripts (historical parallel)
Prerequisites
- 9560: Text Files - What files contain
- 9570: Processes - What uses files
- 9580: Memory Management - Temporary storage (RAM) vs persistent (disk)
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:
- File (contains data: text, binary, whatever)
- Directory (contains other files/directories)
Paths describe location:
- Absolute:
/home/alice/essay.md
(from root) - Relative:
../bob/
(from current 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 Link | Soft Link |
---|---|
Points to inode | Points to filename |
Survives file deletion | Breaks if target deleted |
Same filesystem only | Cross-filesystem OK |
Can't link directories | Can link directories |
Plant lens:
- Hard link = clones (both are the same plant)
- Soft link = signpost (points to where plant is)
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:
- Size: Bytes
- Permissions: Who can read/write/execute
- Owner: User and group
- Timestamps: Access, modify, change (ctime)
- Inode number: File's identity
- Links: How many names point to this inode
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:
- Catalog (like inodes - metadata about each manuscript)
- Location (which shelf, which room - like filesystem path)
- Cross-references (like soft links - "see also...")
- Preservation (copying degraded texts - like backups!)
Same principles:
- Hierarchical structure (easier to find things)
- Metadata (author, date, subject)
- Paths (navigation system)
- Preservation (redundancy, copying)
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
- 9560: Text Files - What files contain
- 9570: Processes - What uses files
- 9505: House of Wisdom - Manuscript organization
- 9595: Package Managers - Filesystem + metadata at scale
External Resources
- "The Linux Filesystem Explained" - Comprehensive guide
man hier
- Filesystem hierarchy documentationman inode
- Inode structure details- ext4, btrfs, ZFS - Modern filesystem implementations
Reflection Questions
- Why hierarchical? (Why not flat? What about tags/labels instead of directories?)
- Is the FHS optimal? (Why
/usr/bin
vs/bin
? Historical reasons or good design?) - Should everything be a file? (Unix says yes. Windows uses more abstractions. Who's right?)
- What if filesystems were immutable? (Nix store is append-only! What if ALL filesystems were?)
- How would you organize 10 million files? (Hierarchical structure helps, but at what depth?)
Summary
Filesystems provide:
- Hierarchical organization (directories contain directories/files)
- Persistent storage (survives power loss, unlike RAM)
- Metadata (permissions, timestamps, ownership)
- Uniform interface ("everything is a file")
Key Concepts:
- Inodes: File identity (metadata + data blocks)
- Paths: Navigation (absolute vs relative)
- Hard links: Multiple names, same inode
- Soft links: Pointer to filename (breaks if target deleted)
Unix Filesystem Hierarchy:
/
- Root (top of tree)/home/
- User files/etc/
- Configuration (text files!)/var/
- Variable data (logs, caches)/usr/
- User programs and libraries
"Everything is a File":
- Regular files (data)
- Directories (containers)
- Devices (hardware access)
- Processes (
/proc/
- virtual) - Pipes (IPC via filesystem)
Key Insights:
- Hierarchy enables organization at scale (millions of files)
- Inodes separate identity from naming (powerful abstraction)
- Text configuration (
/etc/
) enables version control, portability - Virtual filesystems (
/proc/
,/dev/
) show power of "everything is a file"
Historical Parallel:
- House of Wisdom organized manuscripts hierarchically
- Modern filesystem = digital library catalog
- Same principles: hierarchy, metadata, preservation, cross-references
In the Valley:
- We respect the filesystem (persistent garden, seed bank)
- We use hierarchy wisely (not too deep, not too flat)
- We version control config (
/etc/
is text - git it!) - We understand inodes (enables hard links, reflinks, deduplication)
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:
- Phase: 1 (Foundations)
- Week: 3
- Prerequisites: 9560, 9570, 9580
- Concepts: Filesystem, hierarchy, inodes, hard links, soft links, FHS, "everything is a file"
- Next Concepts: Permissions, access control, security model
- Plant Lens: Seed bank (persistent storage), branches (directories), fruits (files), routes (paths)
Copyright © 2025 kae3g | Dual-licensed under Apache-2.0 / MIT
Competitive technology in service of clarity and beauty