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. Pippa rarely uses it 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.

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.