Computing Foundations › The Command Line › Day 9

Day 9: Navigating the Filesystem: Paths, Files, and Permissions

Day 9 of 365 — 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.

Course
Computing Foundations
Category
The Command Line
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

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

  1. 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
  2. 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
  3. 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.
  4. 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:

Prerequisites

Why this matters


The idea in plain language

Diagram: the four special path symbols and what each means


Historical background

Diagram: separate drive namespaces compared with one mounted tree


What it is — and what it is not

Diagram: a filesystem tree rooted at slash, showing an absolute and a relative path to the same file

It is not:


Why it was created and what problems it solves


How it works

Absolute and relative

Diagram: absolute paths compared with relative paths

Where you are, and moving

CommandWhat it does
pwdPrint the absolute path of where you are
cd DIRMove to DIR, absolute or relative
cd ..Move up to the parent
cd ~ or cdReturn home
cd -Return to the previous directory
lsList names
ls -lLong listing: permissions, owner, size, date
ls -aInclude hidden entries
ls -lhLong listing with readable sizes (4.0K, 2.3M)

Permissions: who may do what

Diagram: converting permission letters into octal digits

Diagram: decoding the permission string dash r w x r dash x r dash dash into user, group, and other, and into octal 754

The same bits have a numeric spelling you will see constantly:


An everyday analogy

Diagram: how to locate what is consuming disk space

An office building.

The buildingThe filesystem
The street addressAn absolute path
”Two doors down”A relative path
The lobby/
Your deskYour home directory
Whose desk it isThe owner
Your departmentThe group
The door lockThe permission bits
The service corridorHidden dotfiles

Examples in practice

Diagram: how dot-prefixed files are hidden from ordinary listings


Implications: security, privacy, performance, scalability, and cost

Diagram: unsafe and safe habits around deletion


Alternatives: free, open source, and commercial

ToolTypeWhat it adds
ls, cd, pwdFree, built inEverything in this lesson
treeFree, open sourceThe hierarchy drawn as a tree
eza / exaFree, open sourcels with colour, icons and git status
fdFree, open sourceA friendlier, faster find
ranger, nnnFree, open sourceA file browser inside the terminal
Finder / ExplorerBundledGenuinely better for visual browsing

Diagram: what read, write and execute mean on a file compared with a directory

TermWhat it actually is
PathA route through the tree to one file
DirectoryA file whose contents are a list of names and locations
FolderThe graphical interface’s word for a directory
Mount pointA directory where another filesystem is attached
SymlinkA file whose contents are another path
InodeThe record holding a file’s metadata and block locations

When to use it — and when not to

Diagram: the commands that create, copy, move and delete files


The AI connection


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 doingCommand
Find out where you arepwd
Build a nested tree in one stepmkdir -p lab/data/raw
Create a filetouch lab/data/raw/notes.txt
Reach it two waysls /full/path/... then cd lab/data and ls raw
See the permission bitsls -l lab/data/raw/notes.txt
Make a script runnablechmod +x run.sh then ./run.sh
Reveal what was hiddenls -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

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. What does the single forward slash / mean at the very start of a path?

  1. The current working directory
  2. A hidden file
  3. The user's home directory
  4. 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?

  1. An absolute path starts at /; a relative one starts where you are
  2. Absolute and relative paths can never point at the same file
  3. An absolute path starts from your current directory; a relative path starts from /
  4. 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?

  1. The current directory
  2. The parent directory, one up
  3. Your home directory
  4. 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?

  1. ls
  2. ls -h
  3. ls -la
  4. 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?

  1. 644
  2. 755
  3. 777
  4. 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?

  1. Running the file as a program
  2. Changing or deleting the file's contents
  3. Viewing the file's contents
  4. 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?

  1. It only works if you are an administrator
  2. It deletes everything under a path, with no undo
  3. It permanently changes the file's owner and group
  4. 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?

  1. chmod works only on directories; chown works only on files
  2. chmod deletes a file; chown copies it
  3. chmod sets what is allowed; chown sets who owns it
  4. 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


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.