Terminal · foundation

Absolute vs relative paths

An absolute pathname starts from the filesystem root, while a relative pathname starts from the process's current working directory or another explicitly supplied directory reference.

Why it matters

Choosing the right path form determines whether a command is portable across locations or anchored to one machine layout.

Mental model

How to reason about absolute vs relative paths

Path resolution walks components from a starting directory: / selects the root, while an ordinary first component keeps the current directory as the starting point.

Analogy

An absolute path is a complete postal address; a relative path is a direction such as 'two doors down' that only works from a known starting point.

Examples

See the boundary, not just the happy path

Worked example · Absolute configuration path

cat /etc/hosts

The leading slash anchors resolution at the root directory, so the current working directory does not affect the target.

Worked example · Project-relative test path

python3 ./scripts/check.py

The ./ anchors the script argument at the current directory. The shell still resolves the actual command, python3, through its normal command lookup rules.

Useful contrast · Home expansion is not an absolute-path rule

cat ~/notes.txt

The shell expands an unquoted leading ~ before execution; the resulting pathname is usually absolute, but tilde expansion is separate from pathname resolution.

Common mistakes

Misconceptions to remove early

Assuming a leading slash means project root

On Unix-like systems, / means the filesystem root, not a repository, web application, or current workspace root.

Embedding machine-specific absolute paths

Absolute paths are precise but often reduce portability; project-relative paths or configurable base directories are usually better for shared scripts.

Quick check

Can you predict the result?

1. Which path resolves independently of the current working directory?
  • /opt/terminaster/config.json
  • config.json
  • ../config.json
Answer: /opt/terminaster/config.json
2. From /srv/app, what does ../logs begin resolving from?
Answer: It moves from /srv/app to /srv, then selects /srv/logs.

Keep building

Authoritative references

Make the idea retrievable.

Study this concept with spaced repetition, next to the commands where you use it.

Get Terminaster