Module 1: Terminal BasicsLesson 4 of 7
0%
Lesson 4ยท4 min

Navigating with cd

Move around your file system like a pro

Navigating with cd

The cd command means "change directory". It's how you move around.

Basic Usage

Terminal
$ cd Documents
$
โ–Œ

That's it! You're now in your Documents folder.

See Where You Are: pwd

Lost? The pwd command ("print working directory") shows your current location:

Terminal
$ pwd
/Users/john/Documents
โ–Œ

Common cd Patterns

Terminal
# Go to your home folder
$ cd ~
$ cd # (just cd by itself also works!)
# Go to Desktop
$ cd ~/Desktop
# Go up one folder
$ cd ..
# Go up two folders
$ cd ../..
# Go to root (top of file system)
$ cd /
# Go to previous folder (like browser back button)
$ cd -
โ–Œ

Tip

Tab completion is your best friend! Start typing a folder name and press Tab - the terminal will complete it for you. cd Doc + Tab โ†’ cd Documents/

See What's Here: ls

The ls command lists files and folders:

Terminal
$ ls
Desktop Documents Downloads Pictures
$ ls -la # Show hidden files with details
total 0
drwxr-xr-x 12 john staff 384 Apr 30 10:00 .
drwxr-xr-x 5 john staff 160 Apr 30 09:00 ..
drwx------ 5 john staff 160 Apr 30 10:00 Desktop
drwx------ 10 john staff 320 Apr 30 10:00 Documents
โ–Œ

Putting It Together

Terminal
$ cd ~ # Start at home
$ pwd
/Users/john
$ cd Documents/projects # Go to projects folder
$ pwd
/Users/john/Documents/projects
$ ls # See what's here
my-app website scripts
$ cd my-app # Go into my-app
$ cd ../website # Go to sibling folder
$ cd ~ # Back home!
โ–Œ

Aussie Note

cd without any arguments always takes you home. Like clicking your heels together! ๐Ÿ 

Warning

Folder names with spaces need quotes or escaping: cd "My Folder" or cd My\ Folder Tip: Avoid spaces in folder names when possible.

Practice Exercise

Try this sequence:

  1. Open your terminal
  2. Type pwd to see where you are
  3. Type cd Desktop to go to Desktop
  4. Type ls to see files there
  5. Type cd ~ to go home
  6. Type pwd to confirm

You're navigating! ๐ŸŽ‰