C.W.K.
Stream
Lesson 02 of 12 · published

pwd, cd, ls — The Navigation Trinity

~12 min · pwd, cd, ls, navigation

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

The three commands you'll run a thousand times a day

pwd tells you where you are. cd moves you somewhere. ls shows what's there. Master these three and you can find any file on the system without a GUI.

pwd — print working directory

The shell remembers your current working directory. Every relative path you type is resolved against it. pwd prints it. pwd -P resolves any symlinks in the path so you see the physical location.

cd — change directory

cd path moves you. Special arguments earn their keep:

  • cd with no argument — home directory
  • cd ~ — same thing, explicit
  • cd - — toggle between the two most recent directories (huge time-saver)
  • cd ~user — that user's home (if you have permission)

Zsh adds setopt AUTO_CD: typing a bare directory name (no cd) jumps into it. Pair with the zoxide tool from the modern-tools track and you almost never type cd again.

ls — list directory contents

Plain ls shows visible files only. The flags you'll wear out:

  • -a — include hidden (dotfiles)
  • -l — long format with permissions, owner, size, mtime
  • -h — human-readable sizes (with -l)
  • -t — sort by modification time, newest first
  • -r — reverse sort
  • -S — sort by size
  • -R — recurse into subdirectories

The classic combo: ls -lah = long, all, human-readable. Memorize it; you'll type it more than your name.

Code

Trinity in action·bash
pwd
cd /tmp
pwd
cd -                      # back to where you were
ls -lah
ls -ltrh                  # newest at the bottom — easy to read
AUTO_CD in zsh·zsh
echo 'setopt AUTO_CD' >> ~/.zshrc
source ~/.zshrc
/tmp                      # jumps in without typing cd

External links

Exercise

Run pwd, cd /tmp, pwd, cd -. Then ls -lah in your home directory. Add setopt AUTO_CD to .zshrc, reload, and try jumping into a directory by typing only its name.

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.