Navigating Directories with cd
Introduction
In Lesson 2, you learned to look inside any folder without ever leaving where you stood — ls let you peek, but your location never changed. Now it's time to actually move. The command for that is cd ("change directory"), and the single idea behind it is the path: the address you hand it so it knows where to take you. Some paths are read relative to where you're standing, and others work the same from anywhere on the machine. After every move, you'll run pwd to confirm you landed exactly where you meant to. By the end of this lesson, you'll be able to reach any folder on your Mac and always know where you are.
Your First Move: cd ~
Before we start moving, you need somewhere to go — and it's already there. A folder chain has been prepared for you at ~/Desktop/Projects/travel/photos/2024, with a file named beach.jpg sitting at the bottom of it. You'll learn to build trees like this yourself in Lesson 4; for now, it exists so you can walk through it.
Now for your first real move. The cd command changes your current directory — think of it as walking through a door instead of just looking through it. This matters because everything you do next (creating files, running programs, and listing contents) happens relative to wherever cd last took you. The simplest destination of all is ~, a shorthand that always means your home directory, no matter where you were standing before you typed it.
One detail worth getting right from the start: ~ is not a path that cd understands. It's shell expansion shorthand — before cd runs, the shell rewrites ~ into /Users/alex, so what cd actually receives is a path starting at /. That's why cd ~ behaves identically from every folder on the machine.
Notice the pattern: cd moved us, and pwd immediately confirmed it. That's a habit worth building right now — every time you move, check where you landed. It costs one extra line and saves you from guessing.
Relative Paths
A path is absolute when its expanded form starts at /, and relative when it doesn't — a relative path is read starting from wherever you currently are. (Note the word expanded: ~/Desktop looks like it doesn't start with /, but the shell turns it into /Users/alex/Desktop first, so it's absolute.) This distinction matters because most of the paths you'll type day to day are relative — they're shorter to write, but only make sense in context. Right now we're sitting in ~, so let's use that as our starting point.
That single line walked through three folders at once — Desktop, then Projects, then travel — all in one command. You could keep going the same way, stepping into folders nested even deeper.
Here's the catch worth sitting with: photos/2024 only worked because we were already standing inside travel. If you had typed that exact same path while sitting in /Applications instead, the shell would report an error because /Applications has no photos folder inside it. A relative path isn't wrong or right on its own — it only means something once you know where you're standing when you type it.
