Going back up, going home
You can step into folders with cd. Now learn three ways to step out of them. Together
with last lesson’s cd <folder>, these are the entire navigation toolkit. Truly — there’s
nothing else.
cd .. — one step up
Run cd .. (those are two dots after a space) to move up one folder:
cd ..
The two dots mean “the folder one level above this one.” If you were in
/Users/you/Documents/photos, you’re now in /Users/you/Documents. Run pwd to confirm.
You can stack them:
cd ../..
That’s “up two levels.” ../../.. is three. You’ll rarely go past two — at that point it’s
faster to just type the path you want.
cd ~ — home, no matter where you are
The ~ (tilde) symbol means your home folder — the place you start every terminal session.
Type:
cd ~
You’re home. Doesn’t matter where you were before. Doesn’t matter how deep. One command, and you’re at the kitchen table of your filesystem.
A bare cd with nothing after it does the exact same thing:
cd
Both forms work. Many people just type cd.
The tilde also chains:
cd ~/Desktop
That means “from my home folder, into Desktop.” It works from anywhere — you don’t need to be home first.
cd - — back where I just was
This one is small but addictive. The dash means “the folder I was in just before this one”:
cd -
Use it when you’ve cd-ed somewhere to check one thing and want to jump straight back. It’s
the terminal’s “back button.” You can ping-pong between two folders all day.
You can’t actually get lost
Here is the most important sentence in this whole lesson. Read it twice:
No matter where you are,
cd(alone) takes you home.
Lost? Stuck? Confused about where you ended up after some experiment? Type cd and press
Enter. You’re back at the start. Then run pwd to see your bearings.
The terminal has no “you’ve gone too far” warning. There’s no dead end. As long as you
remember cd, you can always reset.
What you’ve learned
cd ..— one level up.cd ~or justcd— straight home.cd -— back to the previous folder.
Combined with cd <folder> from last lesson, you can now walk anywhere on your computer.
That’s the navigation half of the terminal, done. Next we start making things.