The Linux Filesystem Model and Navigation
The single-rooted tree every Linux path describes, absolute versus relative paths, and the core commands for looking around and changing things safely.
What you'll learn
- Explain the single-rooted Linux filesystem tree and the difference between absolute and relative paths
- Use ls, cd, pwd, mkdir, cp, mv, and rm to inspect and change a filesystem safely
- Explain why rm has no undo, and what that implies about writing rm commands carefully
Explanation
This lesson's browser exercises model shell behavior as JavaScript string/array logic — they never execute real shell commands. Every real command shown here runs only in your own terminal, most concretely in this lesson's guided local lab.
Linux organizes every file and directory into one single tree, rooted at / — there's no separate drive letter per device the way some other systems work; an external drive, a second partition, or a network share is instead mounted at some point within that one tree (/mnt/usb, /media/backup), so ls / always shows the same handful of top-level directories (/home, /etc, /var, /tmp, and others) regardless of how many physical or virtual devices are actually involved. An absolute path (/home/alice/notes.txt) always starts from / and means the same file no matter which directory you're currently in; a relative path (notes.txt, ../projects/app) is resolved starting from your current working directory — pwd prints that current directory, and it's genuinely essential context for correctly interpreting any relative path you see or write.
The core navigation and manipulation commands: ls (list a directory's contents; ls -la adds hidden files and detailed metadata), cd (change the current working directory; cd .. moves up one level, cd ~ or bare cd moves to your home directory), mkdir (create a directory; mkdir -p a/b/c creates every missing intermediate directory in one call), cp (copy; cp -r for a directory's full contents), mv (move or rename — Linux doesn't distinguish; moving a file to a new name in the same directory is a rename), and rm (remove). The single most important fact about rm, worth internalizing precisely rather than just "being careful": there is no trash, no undo, no confirmation prompt by default — rm important-file.txt deletes it immediately and permanently, and rm -rf some/path recursively deletes an entire directory tree with the same finality and the same complete absence of a safety net. This is exactly why this course returns to safe, defensive command construction repeatedly — a mistake here isn't recoverable the way a mistake in most other tools is.
Example
Modeling absolute-vs-relative path resolution as string logic -- no real filesystem or shell is touched by this exercise or any exercise in this course.
function stripTrailingSlash(dir) {
return dir.endsWith("/") ? dir.slice(0, -1) : dir;
}
function resolvePath(currentDir, inputPath) {
if (inputPath.startsWith("/")) {
return inputPath; // absolute -- always means the same thing, regardless of currentDir
}
// relative -- resolved starting from currentDir (a simplified model, ignoring "." and "..")
return stripTrailingSlash(currentDir) + "/" + inputPath;
}
console.log(resolvePath("/home/alice", "/etc/hosts")); // "/etc/hosts" -- absolute, currentDir ignored
console.log(resolvePath("/home/alice", "notes.txt")); // "/home/alice/notes.txt" -- relative, resolved from currentDir
console.log(resolvePath("/home/alice/projects", "notes.txt")); // "/home/alice/projects/notes.txt" -- SAME relative path, DIFFERENT resultTry it yourself
Call resolvePath with currentDir '/var/log' and inputPath 'app.log', and confirm the resolved path.
Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.
Guided exercise
Guided exercise
This models path resolution only -- it does not execute any shell command. Write resolvePath(currentDir, inputPath): if inputPath starts with '/', return it unchanged (absolute); otherwise return currentDir (with any trailing '/' stripped) + '/' + inputPath (relative).
Checks: an absolute path is returned unchanged · a relative path resolves against the current directory · handles a trailing slash on currentDir correctly
Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.
Stuck? Get a hint.
Independent exercise
Independent exercise
This models directory-tree creation logic only -- it does not execute mkdir or touch any real filesystem. Write splitMkdirPParts(path) that returns an array of every intermediate directory 'mkdir -p' would need to create, in order, for a path like 'a/b/c' -> ['a', 'a/b', 'a/b/c'].
Checks: builds every intermediate directory path in order · handles a single-segment path
Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.
Stuck? Get a hint.
Guided local lab
Navigate and Transform a Safe Sample Workspace
Runs on your computerBuild a small, deliberately safe sample workspace on your own machine and practice real navigation and file manipulation commands against it — every command below runs in YOUR terminal; this platform does not execute any of them.
Required tools
- A Linux terminal (or macOS Terminal, or WSL on Windows) (any current version)
- Bash (5.x (or a compatible shell))
Setup
- Open a terminal.
- Create a dedicated, disposable practice folder: `mkdir -p ~/shell-lab/workspace` — everything in this lab stays inside this one folder, so nothing outside it is ever at risk.
- Change into it: `cd ~/shell-lab/workspace`.
Project structure
~/shell-lab/workspace/
notes/
draft.txt
archive/
(empty, created by you)Starter files
notes/draft.txt
TODO: create this file yourself with: echo "first draft" > notes/draft.txt It is listed here only to show the expected final structure -- you create it for real, in your own terminal, using the commands below.
Requirements
- A notes/ directory and an archive/ directory both exist inside ~/shell-lab/workspace.
- notes/draft.txt exists and contains real text you wrote via a real command (not a text editor's save button).
- A copy of draft.txt exists inside archive/, made with cp, not by re-creating the content manually.
- The original notes/draft.txt is renamed to notes/final.txt using mv (not deleted and recreated).
- Nothing outside ~/shell-lab/workspace is created, modified, or deleted at any point in this lab.
Commands to run
Create the two subdirectories
mkdir -p notes archiveCreate a file with real content, without opening an editor
echo "first draft" > notes/draft.txtCopy it into archive/
cp notes/draft.txt archive/draft.txtRename the original
mv notes/draft.txt notes/final.txtConfirm the final structure
ls -la notes archive
Expected behavior
After running the commands above in order, `ls notes` shows final.txt (not draft.txt), `ls archive` shows draft.txt, and `cat archive/draft.txt` prints "first draft" — confirming the copy preserved the original content while the rename only affected the original location.
Verify it yourself
ls notesExpected: final.txt is listed; draft.txt is NOT (it was renamed, not copied)
ls archiveExpected: draft.txt is listed (the copy, unaffected by the later rename in notes/)
cat archive/draft.txtExpected: prints: first draft
cat notes/final.txtExpected: prints: first draft
Troubleshooting
- `mkdir: cannot create directory 'notes': File exists` — You've likely already run this step once — this is harmless; continue with the remaining commands, or start fresh with a new practice folder name.
- `cp: cannot stat 'notes/draft.txt': No such file or directory` — Confirm you're in ~/shell-lab/workspace (check with `pwd`) and that the echo command to create draft.txt actually ran successfully before this step.
- Unsure whether a command is safe to run — Every command in this lab operates only inside ~/shell-lab/workspace, on files you created for this exercise — if you're ever unsure about a command elsewhere, run `pwd` first to confirm your location before anything that creates, moves, or removes files.
Stuck? Get a hint.
Extension challenge
Use `cp -r` to copy the ENTIRE workspace folder to ~/shell-lab/workspace-backup, then confirm with `diff -r` that the two directory trees are genuinely identical.
When you've verified this locally, use the "Mark lesson complete" button below to record your progress.
Common mistakes
- Confusing an absolute path with a relative one when reading or writing a command -- the exact same relative path (like 'notes/draft.txt') means a completely different file depending on the current working directory, which is why checking `pwd` first is a genuinely useful habit, not excessive caution.
- Assuming rm has a trash bin or an undo, the way a graphical file manager typically does -- by default, it has neither; a mistaken rm is permanent and immediate.
- Running a command without first confirming the current directory (pwd) when that command's effect depends on location -- this is exactly the habit that prevents 'I thought I was somewhere else' mistakes.
Knowledge check
Takeaway
Linux uses one single, rooted filesystem tree, and every path is either absolute (unambiguous, starts with /) or relative (depends entirely on the current working directory) — and rm's complete lack of an undo or trash bin makes careful, deliberate command construction a genuine necessity, not excessive caution.
Summary
Linux's filesystem is one tree rooted at /, with other devices mounted within it. Absolute paths are unambiguous; relative paths depend on the current working directory (pwd). ls/cd/mkdir/cp/mv are the core navigation and manipulation commands. rm has no undo or trash by default — deletion is immediate and permanent.
References
Your notes
Notes save automatically.
Finished this lesson?
Mark it complete to track your progress and schedule a future review.
AI tutor
The optional AI tutor isn't enabled in this deployment. All lessons, exercises, quizzes, and search work fully without it.