Exercise 0.2: Navigating Your File System

Moving Around with the cd Command

Author

Chuck Nelson

Published

October 28, 2025

Purpose

Now that you can see where you are and what is around you, it’s time to learn how to move. The cd (change directory) command is your primary tool for navigating your computer’s file system from the command line. Mastering this command is essential for accessing files and running programs in different locations.

What You’ll Accomplish

By the end of this exercise, you will have successfully:

  • Used the cd command to move into subdirectories and parent directories.
  • Understood and used the special directory shortcuts: . (current), .. (parent), and ~ (home).
  • Explained the difference between an absolute path and a relative path.

The cd Command

The cd command is universal across macOS, Linux, and all Windows shells.

Your Task 1: Navigate to a Subdirectory

  1. First, run ls (or dir) to see the folders in your home directory. Pick one, such as Documents or Desktop.

  2. Use the cd command to move into that directory. For example:

    cd Documents
  3. Run pwd again. You should see that your present working directory has changed!

Your Task 2: Navigate Up to the Parent Directory

Every directory has a parent (the directory that contains it). The shortcut for the parent directory is .. (two dots).

  1. From inside the Documents directory, run the following command:

    cd ..
  2. Run pwd again. You will see you are back in your home directory.

Your Task 3: Navigate Home

The most important directory is your home directory. It has a special shortcut, the tilde ~ character.

No matter where you are in your file system, you can instantly return home by typing:

cd ~

On many systems, just typing cd with no arguments will also take you home.

Absolute vs. Relative Paths

This is a critical concept in programming.

  • An Absolute Path is a full path starting from the root of the file system. It is unambiguous and works from anywhere.
    • Examples: /Users/yourname/Documents/MyProject, C:\Users\yourname\Desktop
  • A Relative Path is a path that starts from your current directory. It’s a shorter, more convenient way to access nearby files.
    • Examples: Documents/MyProject (if you are in your home folder), ../Pictures (if you are in your Documents folder)

When you typed cd Documents, you were using a relative path. When you type cd /Users/yourname/Documents, you are using an absolute path.

Verification

Let’s put it all together. Try this sequence of commands:

  1. cd ~ (Go home)
  2. pwd (Confirm you are home)
  3. cd Documents (Move to Documents, using a relative path)
  4. pwd (Confirm you are in Documents)
  5. cd .. (Move up to the parent, which is home)
  6. pwd (Confirm you are home again)

Reflect and Review

ImportantReflection

In your Microsoft Teams Student Notebook, answer the following:

  • What is the command to move to the directory that contains your current directory?
  • What is the difference between an absolute path and a relative path? Give an example of each for your own computer.
  • What is the shortcut character for your home directory?
Back to top