Computing Foundations › The Command Line › Day 9
Day 9: Navigating the Filesystem: Paths, Files, and Permissions
After this lesson you will be able to move confidently through the filesystem tree, describe any location as an absolute or relative path, create and reshape files and directories from the command line, and read and set the read/write/execute permissions that decide who may do what.
Hands-on lab for this lesson
Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-009-navigating-the-filesystem-paths-files-and
- Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git cd ai-roadmap-365.github.io - Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
cd labs/sections/computing-foundations/day-009-navigating-the-filesystem-paths-files-and - Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
- Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
bash tests/run_tests.sh # or the test command named in the lab README
You can also open the lab as a local page (works offline, shows the file tree and expected output).
Learning objectives
By the end of this lesson you will be able to:
- Describe the filesystem as a single tree rooted at / and explain the meaning of the special path symbols /, ., .., and ~
- Write both an absolute path and a relative path to the same file, and explain how each depends (or does not depend) on the working directory
- Navigate and inspect the tree with pwd, cd, and ls (including the -l, -a, and -la flags) and read every field of an ls -l listing
- Create, copy, move, and remove files and directories with mkdir, touch, cp, mv, and rm, and explain why rm -rf is dangerous and how to use it safely
- Decode a permission string such as -rwxr-xr-- into user/group/other read/write/execute, and translate between the rwx form and octal notation like 754
- Use chmod to make a file executable and explain, with chown and the execute bit, why permissions matter for security and for turning a data file into a runnable script
Prerequisites
- A computer running macOS or Linux (or Windows with WSL) and the ability to open a terminal
- Days 1 to 8 of this course, including first contact with the command line
Why this matters
-
Every dataset, model checkpoint and config file you touch lives at a path, and wrong paths are the most common cause of a failed run.
-
Permission deniedis a permissions problem, and today you learn to read and fix it rather than reaching blindly forsudo. -
chmod +xis why your script runs. Without it, a perfectly good script is inert data. -
Remote machines have nothing but paths. No file browser, no dragging, no double-clicking.
-
rm -rfwill be the most dangerous thing you type this week. Today you learn why, before you learn it the other way.
The idea in plain language
-
The filesystem is one tree, with a single root written
/. Everything hangs beneath it, including other disks. -
A path is a route through that tree, and every file has exactly one place in it.
-
An absolute path starts at the root and works from anywhere.
-
A relative path starts where you are standing, which is why “it worked on my machine” so often means “I ran it from a different directory”.
-
Permissions decide who may read, change and run each thing. They are three letters, repeated three times, and they explain almost every access error you will meet.
Historical background
-
Unix chose one tree, deliberately. Other systems of the era gave each disk its own separate namespace; Unix mounted everything into a single hierarchy.
-
That is why Unix has no drive letters. A second disk appears as a directory somewhere in the tree, not as
D:. -
The top-level layout is a convention with a standard.
/binfor programs,/etcfor configuration,/homefor users,/usrfor the bulk of the system — codified as the Filesystem Hierarchy Standard. -
macOS keeps the same shape with different names, notably
/Usersrather than/home, because it descends from BSD by way of NeXT. -
Permissions arrived with multi-user machines in the 1970s, and the nine bits you will read today have not changed since.
What it is — and what it is not
-
Read from the top. The root branches into
bin,etc,homeandusr. Insidehomeare the users; alice’s directory is what~expands to. -
Two routes reach one file.
/home/alice/projects/data/notes.txtis absolute and valid from anywhere.data/notes.txtis relative and only means something when you are standing inprojects. -
Same file, two names. That is the entire distinction.
It is not:
-
Not a metaphor for the disk. The tree is an invention; the disk is numbered blocks, as Day 5 showed.
-
Not a security boundary by itself. Hidden files are hidden by convention; permissions are the actual mechanism.
-
Not the same as the graphical file browser. The browser hides things, renames things and invents folders that do not exist on disk.
Why it was created and what problems it solves
-
Naming. Billions of numbered blocks are unusable. Names, nested, are how humans find anything.
-
One namespace. Every file has one path, so a path can be written down, shared, scripted and depended on.
-
Ownership. Multi-user machines needed to know whose file this is, which is what the owner field records.
-
Access control. Not everyone should read the payroll, and not everyone should edit the system configuration.
-
Extensibility. Mounting lets a new disk, a network share or a virtual filesystem appear as a directory, with no new syntax to learn.
How it works
Absolute and relative
-
An absolute path begins with
/. It is unambiguous from any working directory. -
A relative path does not. It is interpreted from wherever you currently are.
-
Use absolute paths in scripts and configuration, where you cannot know the working directory.
-
Use relative paths interactively, where you can see where you are standing.
-
~expands to your home directory before the program runs — the shell does it, not the program.
Where you are, and moving
| Command | What it does |
|---|---|
pwd | Print the absolute path of where you are |
cd DIR | Move to DIR, absolute or relative |
cd .. | Move up to the parent |
cd ~ or cd | Return home |
cd - | Return to the previous directory |
ls | List names |
ls -l | Long listing: permissions, owner, size, date |
ls -a | Include hidden entries |
ls -lh | Long listing with readable sizes (4.0K, 2.3M) |
- Flags combine.
ls -laisls -l -amerged. ls -lawill be your most-typed command this course. Make it a reflex.pwdis your anchor whenever you feel lost, and you will.
Permissions: who may do what
-
Every file records an owner, a group, and nine permission bits.
-
Read the string left to right. In
-rwxr-xr--, the leading-says ordinary file (dwould say directory). -
rwx— the user (owner): read, write, execute. -
r-x— the group: read and execute, not write. A dash means absent. -
r--— other: read only.
The same bits have a numeric spelling you will see constantly:
-
Within each group of three, read is 4, write is 2, execute is 1. Add up what is present.
-
rwx= 7,r-x= 5,r--= 4, so-rwxr-xr--is 754. -
chmod 754 script.shsets exactly those bits. -
chmod +x script.shadds execute for everyone;chmod u+w notes.txtadds write for the owner;chmod go-r secret.txtremoves read for group and other. -
chown alice notes.txtreassigns the owner, and usually needssudo— handing your file to another user is a system-level act, while changing permissions on files you already own is not. -
This is what “make the script executable” means. A freshly written
train.shis data untilchmod +xturns on the execute bit.
An everyday analogy
An office building.
| The building | The filesystem |
|---|---|
| The street address | An absolute path |
| ”Two doors down” | A relative path |
| The lobby | / |
| Your desk | Your home directory |
| Whose desk it is | The owner |
| Your department | The group |
| The door lock | The permission bits |
| The service corridor | Hidden dotfiles |
-
An absolute address works from anywhere in the city. “Two doors down” only works if someone knows where you are standing.
-
You may be allowed into a room but not to move its furniture. That is read without write.
-
You may be allowed to walk through a corridor without reading the door signs. That is execute without read on a directory.
Examples in practice
-
No such file or directoryon a path that plainly exists: you are in a different working directory than you assumed. Runpwd. -
Permission deniedrunning a script you just wrote: the execute bit is off.chmod +xit. -
A
.envfile a tutorial says to edit and you cannot see:ls -a. -
cpon a directory failing: it needs-r. -
A path with a space breaking a command: quote it, or the shell splits it into two arguments.
Implications: security, privacy, performance, scalability, and cost
-
Security: permissions are the real mechanism, hidden files are not. A dot prefix protects nothing from anyone who types
ls -a. -
chmod 777is not a fix. It is world-writable, and it is how a shared machine becomes someone else’s. If a permission problem needs 777, the problem is ownership, not permissions. -
Privacy:
~/.sshand~/.awshold credentials, and their permissions matter enough that SSH refuses to work if they are too open. -
Performance: deep trees of tiny files are slow, because each one costs a syscall — the Day 6 boundary again.
-
Cost: the expensive mistake is deletion, not storage. Storage is cheap; regenerating a dataset is not.
Alternatives: free, open source, and commercial
| Tool | Type | What it adds |
|---|---|---|
ls, cd, pwd | Free, built in | Everything in this lesson |
tree | Free, open source | The hierarchy drawn as a tree |
eza / exa | Free, open source | ls with colour, icons and git status |
fd | Free, open source | A friendlier, faster find |
ranger, nnn | Free, open source | A file browser inside the terminal |
| Finder / Explorer | Bundled | Genuinely better for visual browsing |
- Learn the built-ins first. They exist on every server you will ever connect to; the nicer tools do not.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| Path | A route through the tree to one file |
| Directory | A file whose contents are a list of names and locations |
| Folder | The graphical interface’s word for a directory |
| Mount point | A directory where another filesystem is attached |
| Symlink | A file whose contents are another path |
| Inode | The record holding a file’s metadata and block locations |
When to use it — and when not to
-
Use absolute paths anywhere the working directory is not guaranteed — scripts, cron jobs, configuration files, container definitions.
-
Use relative paths inside a project, so the project can be moved or cloned anywhere and still work.
-
Use
chmodto grant the least that works, not the most that is convenient. -
Do not use the filesystem as a database. A directory with a million files is a performance problem and a backup problem.
-
Do not fix permission errors with
sudoreflexively. Read the error, check ownership, and understand why before escalating.
The AI connection
-
Dataset paths in a config file are absolute for a reason: the training job may start from a working directory nobody predicted.
-
Checkpoint directories need write permission, and a run that trains for six hours and then cannot save is a specific kind of painful.
-
Containers mount host directories, and a permission mismatch between the user inside and the user outside is one of the most common container failures.
-
~/.cache/huggingfaceis a dotfile directory that will quietly grow to tens of gigabytes. Knowingls -aanddu -shis how you find it. -
A million small training files is a filesystem problem before it is a model problem.
Knowledge check
quiz:
question: "You can list the names inside a directory but every attempt to open a file in it fails, even files you own. Which permission is missing?"
options:
- "Execute on the directory, which is what grants the right to reach through it"
- "Read on the directory, which is what grants the right to see inside it"
- "Write on the files, which is what grants the right to open them"
- "Execute on the files, which is what grants the right to read them"
answer_index: 0
explanation: "On a directory, read lets you list the names and execute lets you traverse into it. Read without execute is exactly the state where you can see what is there and reach none of it."
Hands-on exercise
Build a small tree, walk it both ways, and set its permissions. Worked through fully in the Day 9 lab directory.
| What you are doing | Command |
|---|---|
| Find out where you are | pwd |
| Build a nested tree in one step | mkdir -p lab/data/raw |
| Create a file | touch lab/data/raw/notes.txt |
| Reach it two ways | ls /full/path/... then cd lab/data and ls raw |
| See the permission bits | ls -l lab/data/raw/notes.txt |
| Make a script runnable | chmod +x run.sh then ./run.sh |
| Reveal what was hidden | ls -a ~ |
Expected output
/Users/you/lab/data
-rw-r--r-- 1 you staff 0 Aug 30 10:14 notes.txt
-rwxr-xr-x 1 you staff 31 Aug 30 10:15 run.sh
-rw-r--r--is 644 — owner reads and writes, everyone else reads.-rwxr-xr-xis 755, and thexis what./run.shneeded.
Validate your work
- You reached the same file by an absolute and a relative path
- You can state your current directory without guessing
- You read a permission string and converted it to octal by hand
- You made a script executable and ran it with
./ - You found at least three dotfiles in your home directory
-
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
./run.sh: Permission denied. The execute bit is off.chmod +x run.sh. -
run.sh: command not foundwhen the file is right there. The current directory is not on PATH, by design. Use./run.sh. -
mkdir: File exists. Use-p, which succeeds quietly when the directory is already there. -
A path with spaces splits into two arguments. Quote it:
"My Folder/file.txt".
Common mistakes
-
Assuming the working directory. Run
pwdbefore blaming the path. -
Reaching for
chmod 777. It is almost never the right answer and always a security hole. -
Using
rm -rfbeforels. Look at what you are about to destroy. -
Forgetting
-roncpand wondering why the directory did not copy.
Practice assignment
-
Build a five-level nested tree with one command, then navigate to the bottom using only relative paths, and back to the top using only
... -
Set four different permission combinations on four files, predict each octal value before running
ls -l, and check yourself. -
Find every dotfile in your home directory and identify what created three of them.
-
Create a directory you can list but not enter, then explain the error you get.
-
Measure a directory’s size with
du -shand find the largest thing in it.
Extension challenge
-
Find your ten largest files with
duandsort, and reclaim some space deliberately rather than by guessing. -
Break a symlink on purpose. Create one, delete its target, and observe what
ls -lreports. Explain why the link survives its target. -
Reproduce the container permission problem. Create a file as one user, then try to modify it with a different user id — this is exactly the mismatch that breaks mounted volumes.
-
Read
man chmodon the sticky bit, then explain why/tmpis world-writable and still safe.
Quiz
Q1. What does the single forward slash / mean at the very start of a path?
- The current working directory
- A hidden file
- The user's home directory
- The root of the filesystem tree
Show answer
Answer: D. The root of the filesystem tree
A leading / is the root directory, the one point from which every file and directory on a macOS or Linux system descends. In the middle of a path, / instead separates one name from the next.
Q2. Which statement about absolute and relative paths is correct?
- An absolute path starts at /; a relative one starts where you are
- Absolute and relative paths can never point at the same file
- An absolute path starts from your current directory; a relative path starts from /
- Relative paths only work for directories, never for files
Show answer
Answer: A. An absolute path starts at /; a relative one starts where you are
An absolute path begins at the root / and is valid no matter where you are standing, while a relative path begins from your current working directory and depends on it. Both can name the same file.
Q3. In a path, what does .. mean?
- The current directory
- The parent directory, one up
- Your home directory
- A hidden file
Show answer
Answer: B. The parent directory, one up
A single dot (.) means the current directory, while two dots (..) mean its parent — the directory one level up. The tilde (~) means your home directory.
Q4. Which command shows a long listing that also includes hidden files whose names start with a dot?
- ls
- ls -h
- ls -la
- pwd -a
Show answer
Answer: C. ls -la
The -l flag gives the long listing (permissions, owner, size, date) and the -a flag includes hidden dot-files; combined as ls -la they show a detailed listing of everything in the directory.
Q5. The permission string -rwxr-xr-- corresponds to which octal number?
- 644
- 755
- 777
- 754
Show answer
Answer: D. 754
Within each group of three, read is 4, write is 2, execute is 1. So rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, and r-- = 4+0+0 = 4, giving 754.
Q6. For a plain file, what does the execute (x) permission allow?
- Running the file as a program
- Changing or deleting the file's contents
- Viewing the file's contents
- Renaming the file
Show answer
Answer: A. Running the file as a program
For a file, read (r) allows viewing its contents, write (w) allows changing them, and execute (x) allows running it as a program — which is why making a script runnable means adding the execute bit.
Q7. Why is the command rm -rf considered especially dangerous?
- It only works if you are an administrator
- It deletes everything under a path, with no undo
- It permanently changes the file's owner and group
- It sends files to the Trash, which then fills up
Show answer
Answer: B. It deletes everything under a path, with no undo
The -r flag makes rm recurse into directories and -f suppresses confirmation prompts, so rm -rf erases an entire tree at once with no Trash and no undo — a mistyped or wrong path can destroy far more than intended.
Q8. What is the difference between chmod and chown?
- chmod works only on directories; chown works only on files
- chmod deletes a file; chown copies it
- chmod sets what is allowed; chown sets who owns it
- They are two names for the same command
Show answer
Answer: C. chmod sets what is allowed; chown sets who owns it
chmod ("change mode") sets the read/write/execute permissions on a file, while chown ("change owner") reassigns which user and group own it. Changing owners is a system-level act that usually needs administrator rights; changing permissions on your own files does not.
Glossary
- path
- A sequence of directory names separated by slashes that spells out the route to a file or directory in the filesystem tree.
- absolute path
- A path that starts at the root directory (/) and gives the full route from the top, so it means the same thing no matter what the current directory is.
- relative path
- A path that starts from the current working directory rather than from the root, so its meaning depends on where you currently are.
- working directory
- The directory a shell is currently "in," from which relative paths are interpreted; printed by the pwd command.
- home directory
- The personal directory where a user's own files live and where a terminal usually starts; abbreviated by the shell as the tilde (~).
- root directory
- The single directory at the top of the filesystem tree, written as a lone forward slash (/), under which everything else lives.
- directory
- A named list that maps names to files and to other directories, forming the branches of the filesystem tree (called a "folder" in graphical tools).
- hidden file
- A file or directory whose name begins with a dot, which plain ls and most file browsers skip by default; revealed with ls -a.
- permission
- A rule recording whether a class of user (owner, group, or other) may read, write, or execute a given file or directory.
- chmod
- The command that changes a file or directory's permissions, using either symbolic form (such as +x) or octal form (such as 754).
- octal notation
- A three-digit way of writing permissions in which each digit is the sum, within one class, of read (4), write (2), and execute (1) — for example, 754.
- symbolic link
- A small special file that points at another path, so following it reaches the target; proof that a path is a name for a file rather than the file itself.
- execute permission
- The permission (x) that, for a file, allows it to be run as a program, and for a directory, allows entering it and reaching items through it.
Sources and further reading
- The Linux Command Line — William Shotts (accessed 2026-07-12) — A thorough, beginner-friendly guide to the shell, navigation, files, and permissions.
- The Missing Semester of Your CS Education — The Shell — MIT (accessed 2026-07-12) — Practical lecture and exercises on the shell and working with files.
- Filesystem Hierarchy Standard — Wikipedia (accessed 2026-07-12) — The conventional meaning of top-level directories such as /bin, /etc, /home, and /usr.
- File-system permissions — Wikipedia (accessed 2026-07-12) — The read/write/execute model for user, group, and other, and octal notation.
- GNU Coreutils Manual — GNU (accessed 2026-07-12) — The authoritative reference for ls, cp, mv, rm, mkdir, chmod, and chown.
Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.