Back to Blog

Zsh Tutorial: Navigate Files Like a Pro | cd, pwd, ls Commands (Lesson 2)

Sandy LaneSandy Lane

Video: Zsh Tutorial: Navigate Files Like a Pro | cd, pwd, ls Commands (Lesson 2) by Taught by Celeste AI - AI Coding Coach

Take the quiz on the full lesson page
Test what you've read · interactive walkthrough

Zsh Lesson 2: Navigate the File System with cd, pwd, ls

pwd shows where you are. cd path changes directory. cd ~ to home, cd - to previous, cd .. to parent. ls lists; -l long, -a hidden, -h human-readable. The four commands you'll use thousands of times.

The terminal lives in some directory at all times. Knowing where you are and how to move is the foundation of everything else.

pwd: print working directory

pwd
# /Users/alice

Shows the current directory's full path. The first thing to type when you're disoriented.

cd: change directory

cd Documents
pwd
# /Users/alice/Documents

cd ..
pwd
# /Users/alice

cd path moves to path. The path can be:

  • RelativeDocuments (looked up from current dir).
  • Absolute/Users/alice/Documents (always from root).
  • Special.. (parent), . (current), ~ (home), - (previous).

Path shortcuts

cd ~              # home directory
cd ~/Downloads    # absolute path from home
cd -              # back to previous dir
cd                # alone, defaults to home

~ (tilde) is your home directory — /Users/<you> on macOS.

cd - toggles between two directories. Useful when bouncing between two paths:

cd ~/work/project
cd ~/Downloads
cd -    # back to ~/work/project
cd -    # back to ~/Downloads again

ls: list directory contents

ls
# Applications  Desktop  Documents  Downloads  Library  Movies  Music  Pictures

ls alone lists the current directory.

ls -l: long format

ls -l
# total 16
# drwxr-xr-x   3 alice  staff   96 May  8 10:00 Documents
# -rw-r--r--   1 alice  staff  342 May  8 09:15 notes.txt

Each row shows:

  1. Permissionsdrwxr-xr-x. First char: d directory, - regular file, l symlink. Then three triplets for owner/group/others (rwx = read/write/execute).
  2. Hard link count — usually 1 for files, 2+ for directories.
  3. Owneralice.
  4. Groupstaff.
  5. Size — bytes.
  6. Modification timeMay 8 09:15.
  7. Name — the file or directory.

ls -a: include hidden files

ls -a
# .  ..  .DS_Store  .gitignore  .zshrc  Documents  Downloads

Files starting with . are hidden by default. -a shows them. The . and .. entries are always present (current and parent).

ls -la: combine flags

ls -la
# drwx------+ 18 alice  staff   576 May  8 10:00 .
# drwxr-xr-x   6 root   admin   192 Apr 30 14:22 ..
# -rw-------   1 alice  staff  3072 May  8 10:00 .DS_Store
# -rw-r--r--   1 alice  staff   245 May  8 09:50 .gitignore
# -rw-r--r--   1 alice  staff  1923 May  8 10:00 .zshrc
# drwxr-xr-x   3 alice  staff    96 May  8 09:15 Documents

Long format + hidden. The standard "show me everything."

ls -h: human-readable sizes

ls -lh
# -rw-r--r--   1 alice  staff   1.9K May  8 10:00 .zshrc
# -rw-r--r--   1 alice  staff   3.2M May  8 09:00 photo.jpg
# -rw-r--r--   1 alice  staff   1.5G May  7 16:45 video.mp4

-h converts byte counts to KB/MB/GB. Without it, you'd see 1923, 3145728, 1610612736 — much harder to read.

ls a specific directory

ls Documents
ls -l Documents
ls /usr/local/bin

ls path lists path instead of the current directory.

Combining short flags

These all mean the same thing:

ls -l -a -h
ls -lah
ls -alh

Short flags can stack. Order doesn't matter for these.

A typical session

pwd                 # where am I?
ls                  # what's here?
cd Documents        # go in
ls -l               # detailed listing
cd projects/web
ls -lah
cd ../..            # up two levels
cd ~                # home

Most terminal use is some variation of this loop: navigate, look, navigate.

Path autocomplete with Tab

cd Doc<Tab>         # → cd Documents/
cd ~/Downl<Tab>     # → cd ~/Downloads/
ls /usr/lo<Tab>     # → ls /usr/local/

Always Tab. Don't type out long paths.

If multiple matches, Tab again shows a menu:

cd Do<Tab>
# Documents/  Downloads/

Use arrow keys to pick.

. and ..

ls .                # current directory (same as `ls`)
ls ..               # parent directory
ls ../..            # two levels up
cd ../../sibling    # go up two, then into sibling

. always means "where I am right now." .. always means "one level up."

./script.sh runs script.sh from the current directory — needed because . isn't on $PATH (lesson 6).

Disk shortcuts

Common macOS paths you'll navigate often:

cd ~                # /Users/<you>
cd ~/Desktop
cd ~/Documents
cd ~/Downloads
cd ~/Library        # hidden in Finder; visible to terminal
cd /Applications
cd /tmp             # temp files
cd /                # filesystem root

/Users/Shared is also useful — accessible to all users.

File vs directory

In ls -l, the first character tells you:

drwxr-xr-x  Documents       <- d = directory
-rw-r--r--  notes.txt       <- - = regular file
lrwxr-xr-x  link -> target  <- l = symlink

Or: directories end with / if you alias ls to ls -F (lesson 5).

Common stumbles

cd with a typo silently fails. Actually it errors but doesn't move you. Always pwd after a confusing cd.

Spaces in paths. cd My Documents errors — shell sees two arguments. Quote: cd "My Documents". Or escape: cd My\ Documents. Or rename your directories to avoid spaces.

Case sensitivity. macOS default file system is case-INsensitive for paths but case-PRESERVING for display. cd documents and cd Documents both work; the display is correct.

Hidden files everywhere. Once you ls -a, your home is full of .dotfiles from every app you've ever used. Don't randomly delete them.

ls * expands first. If a directory has 10,000 files, ls *.txt may exceed the argument limit. Use find (lesson 21) for huge directories.

Trailing slash on cp. cp file.txt dir works but is ambiguous. cp file.txt dir/ is unambiguous — definitely treat dir as a directory.

What's next

Lesson 3: file operations. touch, mkdir, cp, mv, rm, and wildcards.

Recap

pwd shows current directory. cd path changes; cd ~ home, cd - previous, cd .. parent. ls lists; -l long, -a hidden, -h human-readable, -la is the standard "show everything." Tab-complete paths — never type them in full. . is current dir, .. is parent. Watch for spaces (quote them) and don't blindly delete .dotfiles from your home.

Next lesson: file operations.

Ready? Take the quiz on the full lesson page →
Test what you've learned. Watch the lesson and try the interactive quiz on the same page.