Skip to content
C.W.K.
Stream
Lesson 05 of 12 · published

Home, Current, Parent — ~ . ..

~10 min · tilde, shortcuts, navigation

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

The four characters that save your life

Almost every shell has the same four shortcuts:

  • ~ — your home directory ($HOME). The shell expands it before running the command.
  • . — the current directory. Often used as ./script.sh to disambiguate from a command on PATH.
  • .. — the parent directory. Stack them: cd ../../grandparent.
  • - — only valid with cd; jumps to the previous directory.

Tilde with usernames

~ alone = your home. ~alice = Alice's home (if you have read access). Useful on shared servers. It is uncommon on a single-user Mac, but it shows up in older Linux scripts often.

Tilde and brace expansion

Tilde is a shell expansion, not a directory entry, so it works in places you don't expect. cp ~/.zshrc ~/.zshrc.bak works, but inside single quotes '~/file' stays literal — quotes disable expansion. Just one of the small grammatical traps.

The dotfiles convention

Hidden files start with . by Unix convention. .zshrc, .bashrc, .git, .env — all the configuration sits in your home as dotfiles. ls ignores them by default; ls -A shows them.

The shell expands a tilde first

~ is not an ordinary pathname character understood by every program. The shell expands it before execution, while "~" and strings in configuration files may remain literal. Use an explicit home variable in scripts and application settings.

Dot-dot cannot bypass permissions

A path can contain .., but traversing each real directory still requires execute permission. When a correct-looking path is denied, inspect every directory component rather than only the final file.

For compact notation, identify which layer performs expansion.

Print the fully resolved path as evidence.

Code

Tilde everywhere·bash
cd ~
ls ~/.zshrc ~/.config/
cp ~/.zshrc ~/Desktop/zshrc-backup
echo '~ inside single quotes is literal'
echo "~ inside double quotes is also literal: ~/test"

External links

Exercise

Run echo ~, echo '~', echo "~", echo $HOME. Compare. Note which one stays literal. Then cd ~/.config, cd .., cd - and watch the directory bounce.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.