Project 3: The Filesystem Explorer (ls -R) Clone
A robust clone of the
lscommand that supports recursion (-R) and detailed listing (-l). You will read directories, query file metadata (inodes), and handle permissions formatting.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C |
| Alternative Languages | Rust |
| Difficulty | Level 2: Intermediate |
| Time Estimate | Weekend |
| Knowledge Area | Filesystem / Inodes |
| Tooling | GCC, man pages |
| Prerequisites | C structs, recursion. |
What You Will Build
A robust clone of the ls command that supports recursion (-R) and detailed listing (-l). You will read directories, query file metadata (inodes), and handle permissions formatting.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Directory Traversal: Using
opendir,readdir,closedir. - Stat System Call: Converting
statstruct data into human-readable strings (e.g.,rwxr-xr-x). - Time Formatting: Handling Unix timestamps.
- Recursion: Safely walking directory trees without infinite loops (symlinks).
Key Concepts
- Inodes:
struct statand what it contains. - Directory Entries:
struct dirent. - Bitmasks: Decoding permission bits (
st_mode).
Real-World Outcome
$ ./myls -l
drwxr-xr-x 2 user group 4096 Dec 22 10:00 .
drwxr-xr-x 10 user group 4096 Dec 21 14:00 ..
-rw-r--r-- 1 user group 512 Dec 22 10:01 main.c
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
LEARN_LINUX_UNIX_INTERNALS_DEEP_DIVE.md - “The Linux Programming Interface” by Michael Kerrisk