File System Fundamentals
Summary
This chapter explores the Linux file system hierarchy, teaching you how everything in Linux is organized as files and directories. You'll learn to navigate using absolute and relative paths, understand the purpose of key system directories like /bin, /etc, and /home, and master essential navigation commands. Understanding the file system is crucial for working effectively in Linux.
Concepts Covered
This chapter covers the following 32 concepts from the learning graph:
- File System
- Root Directory
- Home Directory
- Current Directory
- Parent Directory
- Absolute Path
- Relative Path
- Pwd Command
- Cd Command
- Ls Command
- Ls Options
- Hidden Files
- Dot Files
- Directory Structure
- Bin Directory
- Etc Directory
- Var Directory
- Tmp Directory
- Usr Directory
- Opt Directory
- Dev Directory
- Proc Directory
- Home Subdirectories
- Desktop Directory
- Documents Directory
- Downloads Directory
- Tree Command
- File Command
- Stat Command
- Pathnames
- macOS open command
- Open alias on Linux
Prerequisites
This chapter builds on concepts from:
- Chapter 1: Introduction to Operating Systems and UNIX History
- Chapter 2: Getting Started with the Terminal
Everything Is a File (No, Really!)
One of the most mind-bending things about Linux is its philosophy that everything is a file. Not just your documents and photos—EVERYTHING:
- Regular files? Files. ✓
- Directories? Special files that contain other files. ✓
- Your keyboard? A file. ✓
- Your screen? A file. ✓
- Your USB drive? A file. ✓
- Network connections? Files. ✓
- Running processes? Files. ✓
This might sound weird, but it's actually brilliant. Because everything is accessed the same way, you can use the same tools and concepts for nearly everything in the system. Learn to work with files, and you've learned to work with Linux.
In this chapter, we'll explore how Linux organizes its file system—the structure that holds all these files. Think of it as learning the layout of a new city. Once you know the neighborhoods and how the streets connect, you can get anywhere!
Why File System Knowledge Matters
Understanding the file system is like having a map. Without it, you're wandering aimlessly, guessing where things are. With it, you'll know exactly where to find configuration files, executables, logs, and your own data.
The Root of All Files: /
Every Linux file system starts at a single point called the root directory, written as just a forward slash: /
This is the top of the tree—the ultimate parent directory that contains everything else. Unlike Windows, which has separate drives (C:, D:, E:), Linux has ONE unified tree starting at root. Everything—every file, every device, every directory—lives somewhere under /.
1 2 3 4 5 6 7 8 9 10 | |
The tree Command: Your Documentation Best Friend
The diagram above was created using the tree command! While tree isn't built into Linux by default, it's incredibly handy for visualizing directory structures. Install it with sudo apt install tree (or brew install tree on macOS).
It's especially useful for creating documentation in GitHub README.md files—just run tree -L 2 to show two levels of your project structure, copy the output, and paste it into your README inside a code block. Your future self (and collaborators) will thank you!
1 2 | |
Root Directory vs Root User
Don't confuse them! The root directory (/) is the top of the file system. The root user is the administrator account. They share a name because root user's home directory is /root (a directory INSIDE the root directory). Confusing? A little. Just remember: / = file system top, root = admin user.
Home Sweet Home: Your Home Directory
While the root directory contains the whole system, your home directory is your personal space. It's where:
- Your personal files live (Documents, Downloads, Pictures)
- Your configuration files are stored
- You have full permission to create, modify, and delete files
Your home directory is located at /home/username. So if your username is "dan", your home is /home/dan.
There's a super handy shortcut for your home directory: the tilde character ~
1 2 3 4 5 | |
The ~ is incredibly useful:
1 2 3 4 5 6 7 8 | |
Home Subdirectories
Most Linux systems create standard folders in your home directory:
| Directory | Purpose |
|---|---|
| Desktop | Files/folders shown on your desktop GUI |
| Documents | General documents |
| Downloads | Downloaded files (browsers save here by default) |
| Music | Audio files |
| Pictures | Images and photos |
| Videos | Video files |
| Templates | Document templates |
| Public | Files you want to share with other users |
These are just conventions—you can organize your files however you like! But many programs expect these directories to exist.
Where Am I? The Current Directory
At any moment, your terminal is "in" a specific directory called the current directory (also called "working directory" or "present working directory"). When you run commands, they operate relative to this location.
The pwd command (Print Working Directory) tells you where you are:
1 2 | |
That's it! pwd is your "You Are Here" marker on the file system map.
Your shell prompt usually shows the current directory too:
1 2 | |
Lost? Just pwd!
Whenever you're not sure where you are in the file system, type pwd. It's the command-line equivalent of looking at the GPS on your phone.
Moving Around: The cd Command
The cd command (Change Directory) is how you move through the file system. It's like walking from one room to another in a building.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
The Parent Directory: ..
The parent directory is the directory that contains the current one. It's represented by two dots: ..
1 2 3 | |
So if you're in /home/dan/Documents/Projects:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
You can chain .. to go up multiple levels:
1 2 | |
The Current Directory: .
A single dot . represents the current directory. It seems pointless ("I'm already here!"), but it's useful in certain contexts:
1 2 3 4 5 6 7 8 | |
Absolute vs Relative Paths
Here's a crucial concept: there are two ways to specify a location in the file system.
Absolute Paths
An absolute path starts from the root directory / and specifies the complete location:
1 2 3 | |
Absolute paths work from anywhere—they're like giving a complete street address.
Relative Paths
A relative path starts from your current directory:
1 2 3 4 | |
Relative paths are like giving directions from where you are ("go two blocks north, turn left").
| Path Type | Starts With | Example | Works From |
|---|---|---|---|
| Absolute | / |
/home/dan/file.txt |
Anywhere |
| Relative | No / |
Documents/file.txt |
Current directory only |
| Home-relative | ~ |
~/Documents/file.txt |
Anywhere (expands to absolute) |
Diagram: Absolute vs Relative Paths
Understanding Path Types
Type: diagram
Bloom Taxonomy: Understand, Apply Learning Objective: Help students visualize the difference between absolute and relative paths with concrete examples.
Components to show: - File system tree visualization - Current directory highlighted - Three example paths shown: absolute, relative, and home-relative - Arrows showing how each path type navigates the tree
Layout: Tree diagram on left, path examples on right
Example scenario: - Tree showing /home/dan/Documents/Projects/ - Current directory: /home/dan/Documents - Target: /home/dan/Documents/Projects/report.txt
Paths compared: - Absolute: /home/dan/Documents/Projects/report.txt (starts at root, follows full path) - Relative: Projects/report.txt (starts at current dir) - Home-relative: ~/Documents/Projects/report.txt (starts at ~)
Color coding: - Root (/): Red - Home directory: Green - Current directory: Blue highlight - Target file: Gold star
Interactive features: - Click to change "current directory" - See how relative paths change but absolute stays same
Implementation: p5.js or HTML/CSS
Listing Files: The ls Command
The ls command is your window into directories. It lists the contents of a directory:
1 2 | |
By default, ls shows the current directory. You can specify any path:
1 2 3 | |
Essential Ls Options
The ls command becomes much more powerful with ls options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Understanding ls -l Output
The long format (ls -l) shows lots of info:
1 2 3 4 5 6 7 8 9 10 | |
Common file types in the first character:
| Character | Meaning |
|---|---|
- |
Regular file |
d |
Directory |
l |
Symbolic link |
c |
Character device |
b |
Block device |
Hidden Files and Dot Files
In Linux, any file or directory whose name starts with a dot (.) is hidden. These are called hidden files or dot files.
1 2 3 4 5 | |
Why hide files? Mostly to reduce clutter. Your home directory contains LOTS of configuration files that you don't need to see daily:
| Dot File | Purpose |
|---|---|
.bashrc |
Bash shell configuration |
.bash_history |
Your command history |
.config/ |
Application configurations |
.ssh/ |
SSH keys and settings |
.gitconfig |
Git configuration |
.vimrc |
Vim editor settings |
Dot Files are Your Settings
When you customize your shell, editor, or other programs, those settings are usually saved in dot files in your home directory. Learning to edit them gives you tremendous control over your environment!
To show ONLY hidden files:
1 | |
The Linux Directory Structure
Now let's explore the major directories in Linux. Understanding the directory structure helps you know where to find (and put) things.
/bin - Essential Binaries
The bin directory (/bin) contains essential commands that must be available even if other parts of the system aren't mounted. These are commands needed to boot and repair the system:
1 2 | |
Commands like ls, cp, mv, cat, bash—the basics that you've been learning—live here.
Modern Systems: /bin → /usr/bin
On modern Linux systems, /bin is often a symbolic link to /usr/bin. They've been merged for simplicity. You'll still see /bin referenced everywhere though!
/etc - Configuration Files
The etc directory (/etc) contains system-wide configuration files. The name supposedly came from "et cetera" (everything else), but it's now thought of as "Editable Text Configuration."
1 2 | |
Important files in /etc:
| File | Purpose |
|---|---|
/etc/passwd |
User account information |
/etc/hosts |
Local DNS mappings |
/etc/hostname |
System's hostname |
/etc/apt/ |
APT package manager config |
/etc/ssh/ |
SSH server configuration |
Rule of thumb: If you need to configure something system-wide, look in /etc.
/var - Variable Data
The var directory (/var) contains files that change frequently during system operation:
1 2 | |
Most importantly:
/var/log/- System log files (check here when debugging!)/var/cache/- Application cache data/var/www/- Web server files (on web servers)
1 2 3 | |
/tmp - Temporary Files
The tmp directory (/tmp) is for temporary files. Key characteristics:
- Anyone can write here
- Files may be deleted on reboot
- Good for scratch space
1 2 3 4 5 6 7 | |
/usr - User Programs
The usr directory (/usr) contains user-installed programs, libraries, and documentation. Despite the name, "usr" doesn't mean "user"—it historically meant "Unix System Resources."
1 2 | |
Key subdirectories:
/usr/bin/- Most user commands/usr/lib/- Libraries/usr/share/- Shared data (docs, icons, etc.)/usr/local/- Locally compiled/installed software
/opt - Optional Software
The opt directory (/opt) is for optional, third-party software packages. When you install something that doesn't come from your distribution's package manager, it often goes here:
1 2 | |
/dev - Device Files
The dev directory (/dev) contains device files—remember "everything is a file"? Here's where your hardware lives as files:
1 2 | |
Interesting devices:
| Device | What It Is |
|---|---|
/dev/null |
The "black hole"—discards anything written to it |
/dev/zero |
Produces infinite zeros |
/dev/random |
Random number generator |
/dev/sda |
First storage device |
/dev/tty |
Current terminal |
1 2 3 4 5 | |
/proc - Process Information
The proc directory (/proc) is a virtual filesystem that provides information about running processes and the kernel:
1 2 | |
The numbered directories are process IDs. The files provide system info:
1 2 3 4 5 6 7 8 9 10 11 | |
/proc is Virtual
The files in /proc don't actually exist on disk—they're generated on-the-fly by the kernel when you read them. It's like a window into the system's soul!
Diagram: Linux Directory Structure
Linux File System Hierarchy
Type: diagram
Bloom Taxonomy: Remember, Understand Learning Objective: Provide a visual map of the Linux file system hierarchy that students can reference when navigating.
Components to show: - Tree structure starting from / (root) - Major directories with icons representing their purpose - Brief description of each directory's role
Layout: Hierarchical tree diagram
Directories to show (with icons): - / (root) - House foundation icon - /bin - Toolbox icon "Essential commands" - /etc - Gear/settings icon "System configuration" - /home - House icon "User home directories" - /home/dan - Person icon - /home/alice - Person icon - /var - Stack of papers icon "Variable/changing data" - /var/log - Scroll icon "Log files" - /tmp - Trash/temp icon "Temporary files" - /usr - Library icon "User programs" - /usr/bin - Toolbox icon - /usr/lib - Books icon - /usr/local - Pin icon "Locally installed" - /opt - Package icon "Optional software" - /dev - USB/hardware icon "Device files" - /proc - CPU icon "Process info (virtual)"
Color coding: - System critical: Red - Configuration: Orange - User data: Green - Variable data: Blue - Virtual: Purple dashed
Interactive features: - Hover for expanded description - Click to see example contents - Quiz mode: "Where would you find log files?"
Implementation: p5.js or vis-network
Quick Directory Reference
Here's a cheat sheet for the major directories:
| Directory | Contents | Remember It As |
|---|---|---|
/ |
Root of everything | "The trunk of the tree" |
/bin |
Essential commands | "Binary essentials" |
/etc |
Configuration files | "Settings central" |
/home |
User directories | "Your personal space" |
/var |
Changing data, logs | "Variables and logs" |
/tmp |
Temporary files | "Scratch paper" |
/usr |
User programs | "Program library" |
/opt |
Optional software | "Third-party apps" |
/dev |
Device files | "Hardware as files" |
/proc |
Process info | "System's pulse" |
The Tree Command: Visualize the Structure
The tree command displays directories in a tree format—much easier to read than multiple ls commands:
1 2 3 4 5 6 7 8 9 10 | |
Useful tree options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Installing Tree
Tree might not be installed by default. Install it with:
1 2 | |
The File Command: What Kind of File Is This?
The file command tells you what type of file something is, regardless of its extension:
1 2 3 4 5 6 7 8 9 10 11 | |
This is super useful because: - Linux doesn't rely on file extensions - You can identify unknown files - You can verify files are what they claim to be
1 2 3 4 | |
The Stat Command: File Statistics
The stat command shows detailed statistics about a file:
1 | |
Output includes:
- File size
- Block size and count
- Device info
- Inode number
- Access, modification, and change times
- Permissions in multiple formats
1 2 3 4 5 6 7 8 | |
Three important timestamps:
| Time | Meaning | Updated When |
|---|---|---|
| Access (atime) | Last read | File was read |
| Modify (mtime) | Last content change | File contents changed |
| Change (ctime) | Last metadata change | Permissions, owner, etc. changed |
Pathnames: Putting It All Together
Pathnames are the full address of a file in the file system. Everything we've learned comes together here:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Tips for working with pathnames:
- Use Tab completion! (Press Tab to auto-complete paths)
- Use quotes for paths with spaces:
"My Documents/file.txt" - Use wildcards:
ls *.txtmatches all .txt files - Escape spaces with backslash:
My\ Documents/file.txt
Opening Files: The open Command
Want to open a file with its default application from the command line?
macOS: The open Command
On macOS, the macOS open command opens files with their default application:
1 2 3 4 | |
Linux: xdg-open and Aliases
On Linux, use xdg-open:
1 2 3 | |
Since xdg-open is harder to type, many people create an open alias on Linux:
1 2 3 4 5 | |
Other options depending on your desktop environment:
1 2 3 4 5 6 7 8 | |
Practical Navigation Exercises
Let's practice! Try these in your terminal:
Exercise 1: Where Am I?
1 2 3 4 5 6 7 8 9 10 11 | |
Exercise 2: Explore the System
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Exercise 3: Path Practice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Exercise 4: Hidden Files Hunt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Diagram: File System Navigation MicroSim
Interactive File System Navigator
Type: microsim
Bloom Taxonomy: Apply, Analyze Learning Objective: Let students practice navigating the file system with cd, ls, and pwd in a safe simulated environment.
Canvas layout (responsive, ~750px max width): - Top area (100px): Current path display (like a breadcrumb) - Middle area (350px): Visual file system tree - Bottom area (150px): Terminal input and output
Visual elements: - Tree visualization of a simulated file system - Current directory highlighted - Clickable directories in the tree - Terminal-style command input - Output display
Simulated file system: - / - home/ - student/ - Documents/ - report.txt - notes.md - Downloads/ - image.png - .bashrc (hidden) - .config/ (hidden) - etc/ - hosts - hostname - var/ - log/ - tmp/
Interactive elements: - Type commands: cd, ls, pwd, ls -a, ls -l - Click directories in tree to navigate (auto-generates cd command) - "pwd" updates the breadcrumb display - Tab completion simulation
Challenges (optional): 1. "Navigate to your Documents folder" 2. "List hidden files in your home directory" 3. "Go to /var/log and back home in one command" 4. "What's the absolute path of report.txt?"
Behavior: - Commands execute and update visualization - Invalid commands show helpful errors - Tree view highlights current location - Success animations for completed challenges
Implementation: p5.js
Key Takeaways
You've learned how to navigate the Linux file system like a pro! Here's what to remember:
- Everything is a file in Linux—even devices and processes
- The root directory (
/) is the top of the file system tree - Your home directory (
~) is your personal space - Use pwd to see where you are, cd to move around
- Absolute paths start with
/, relative paths don't - Hidden files start with a dot (
.) - Use ls -la to see everything including hidden files
- Key directories:
/bin(commands),/etc(config),/home(users),/var(logs) - tree shows directory structure visually
- file tells you what type of file something is
- stat shows detailed file information
You Can Navigate!
You now have a mental map of the Linux file system. You know where system files live, where your files go, and how to get anywhere using paths. This knowledge will serve you in every future chapter!
What's Next?
Now that you can navigate the file system, it's time to learn how to actually DO things with files! In the next chapter, you'll master:
- Creating files and directories
- Copying, moving, and renaming files
- Deleting files (carefully!)
- Working with file content
Time to stop just looking at files and start manipulating them!
Quick Quiz: File System Fundamentals
- What character represents the root directory?
- What command shows your current directory?
- How do you go to your home directory from anywhere?
- What's the difference between
/etcand/tmp? - How do you list hidden files?
Quiz Answers
/(forward slash)pwd(print working directory)cd ~or justcdwith no arguments/etccontains configuration files;/tmpcontains temporary files that may be deleted on rebootls -a(the -a flag shows all files including hidden)
References
- Linux Filesystem Hierarchy Standard (FHS) Official Documentation - The official specification defining the directory structure and contents of Linux systems.
- Understanding the Linux File System - Linux Foundation's comprehensive guide to the filesystem hierarchy.
- Linux File System Tree Overview - The Linux Documentation Project's detailed breakdown of each directory and its purpose.
- Filesystem Hierarchy Standard on Wikipedia - Historical context and overview of FHS development and adoption.
- Linux Directory Structure Explained - GeeksforGeeks tutorial with clear explanations and visual diagrams of the directory tree.
- Understanding Linux File System: A Complete Guide - Linuxize's beginner-friendly guide to navigating and understanding the filesystem.
- The Linux File System Explained - How-To Geek's accessible explanation of why Linux organizes files differently than Windows.
- Absolute vs Relative Paths Explained - Red Hat's guide to understanding and using different path types effectively.
- Working with Directories in Linux - DigitalOcean tutorial on essential navigation commands.
- Hidden Files and Dotfiles in Linux - nixCraft's guide to working with hidden configuration files.
- Using the Tree Command - TecMint's comprehensive tutorial on visualizing directory structures.
- Linux File Command Tutorial - HowtoForge guide to identifying file types regardless of extensions.
- Understanding File Timestamps - Unix Tutorial's explanation of access, modification, and change times.
- Ryan's Tutorials: Linux File System - Beginner-friendly interactive tutorial on file system navigation.
- Linux Journey: The Filesystem - Interactive lessons on exploring and understanding the Linux filesystem.
- The /proc Filesystem Explained - Official kernel documentation on the virtual /proc filesystem.
- Understanding /dev Directory - Linux.com's guide to device files and their purposes.
- Ubuntu File System Organization - Ubuntu community documentation on filesystem layout.
- Stat Command Examples - GeeksforGeeks tutorial on viewing detailed file metadata.
- Home Directory Best Practices - Opensource.com article on organizing your personal Linux workspace.