Terminal Easy · Lesson 1 · On the house

Absolute vs relative paths

/, ~, ., .., and path joining. Lesson 1 is free — on the house.

Lessons · Terminal Easy · Lesson 1 of 10 · On the house

Absolute vs relative paths

/, ~, ., .., and path joining.

Illustration for Terminal
Lesson 1 is on the house.

An absolute path names a location from the filesystem root. On POSIX shells (WSL, Git Bash, macOS, Linux) it starts with / — e.g. /home/ada/notes.txt. Absolute paths do not depend on your current working directory.

A relative path is resolved from pwd. notes.txt means "notes.txt in the current directory." docs/readme.md means "readme.md inside docs, under here." Leading ./ is optional but explicit: ./notes.txt is the same file as notes.txt.

.. means the parent directory; . means the current directory. cd ../src goes up one level, then into src. ~/ expands to your home directory (same idea as $HOME). Mix carefully: /tmp/../etc still resolves under /, not under home.

Join segments with / (forward slash) even on Windows when you are inside WSL or Git Bash — those shells speak POSIX paths. Prefer absolute paths in scripts that must not care where the user cd'd; prefer short relative paths when you are already inside a project tree.

Misses: treating C:\Users\... as a POSIX path inside bash, assuming docs is absolute because it has no ./, or using .. past / and expecting a different root.

paths

pwd
cd /tmp
pwd
cd ~/Documents
pwd
ls ./
ls ../
Match this when you type.

Quiz

What makes a path absolute on POSIX shells?

Quiz

What does .. mean in a path?

Quiz

Where does a relative path resolve from?

Quiz

What does ~/ expand to?

Check

Match the still for: Absolute vs relative paths.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.