Terminal · foundation

Home, current, and parent paths

In shell use, ~ is commonly expanded to a home-directory path, while . and .. are pathname components referring to the current and parent directories.

Why it matters

These compact forms appear throughout commands and scripts, but they are produced by different mechanisms and resolve relative to different context.

Mental model

How to reason about home, current, and parent paths

The shell expands an eligible tilde first; pathname resolution later interprets . as staying at the current node and .. as moving to its parent, subject to root and symlink semantics.

Analogy

On a building map, ~ is a shortcut to your assigned office, . means this room, and .. means the enclosing floor.

Examples

See the boundary, not just the happy path

Worked example · Create a user-local directory

mkdir -p ~/.local/bin

An unquoted leading tilde is expanded by the shell to the current user's home path before mkdir receives the argument.

Worked example · Run a local script

./build.sh ../artifacts

./build.sh names a file in the current directory, while ../artifacts names a sibling reached through the current directory's parent.

Useful contrast · Quoted tilde

printf '%s\n' '~'

The quoted tilde remains a literal character because quoting suppresses tilde expansion in this position.

Common mistakes

Misconceptions to remove early

Treating ~ as a filesystem entry

Tilde expansion is performed by the shell; system calls and programs receiving a literal ~ do not inherently interpret it as a home directory.

Assuming .. always removes the last written component

Physical resolution across symbolic links can differ from simple textual normalization, so cd -L and cd -P may produce different results.

Quick check

Can you predict the result?

1. Which token is normally expanded by the shell rather than interpreted as a directory entry during pathname resolution?
  • ~
  • .
  • ..
Answer: ~
2. Why does './tool' bypass PATH lookup?
Answer: It contains a slash, so it directly names a path relative to the current working directory.

Keep building

Authoritative references

Make the idea retrievable.

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

Get Terminaster