Skip to content

This guide and website are in beta! Help us make them awesome with your feedback!

Terminal: Navigation Practice

Using the terminal to navigate around the files and directories in your computer (“file tree”) is an essential skill for a developer. Luckily, it doesn’t take long to learn how to do so effectively!

The below exercise will:

  • give you hands-on experience with basic terminal commands so you can find your current position in the file tree and zip across your whole system
  • show how the terminal gives you a different way to access your files by demonstrating the relationship between the commands you type in your terminal and what you visually see in your file explorer

Before you go through this exercise, you should have a basic understanding of:

  1. what terminal you want to use
  2. how to run commands via terminal
  3. what a file path is

While you can read the full articles if you wish, the linked sections should be enough to get started if you prefer to learn through practice. As long as you understand these general concepts, you can follow along with the exercise!

As part of this exercise, we’ll be looking at your terminal and file explorer at the same time. Let’s open both:

  1. Open your terminal program.

    You can find instructions in the Terminal Introduction if you need them!

  2. Open your file explorer program.

    We recommend you arrange your windows so you can see them side by side if possible.

In this section, we’ll show you how the terminal is just a different way to look at and navigate around the same file structure you can see through your day-by-day user interface.

  1. Find your current terminal location.

    In your terminal, run the pwd command. This will show you the path to the directory currently open in your terminal. If you haven’t taken other terminal actions, this will likely be the home directory of your user.

    Terminal window
    pwd
    /users/boba-tan

    A user's home directory traditionally contains personal data that should not be visible by other users. For example, directories like documents/ or desktop/.

  2. Compare this location to your location in the file explorer.

    In the file explorer, check the path of the directory you’re looking at. If needed, navigate to the file path printed in the previous step. Once again, this will likely be the home directory of your user.

    • Directory/
      • Directoryusers/
        • Directoryboba-tan/ <= your current position
  3. List the files at your current terminal position.

    In your terminal, run ls. The output should list the same directories and files you’re seeing in your file explorer window.

    Terminal window
    ls
    Blorbos Coding Documents
    FujoGuide Manga WebbedSite

It’s time to move around (and mess with) your file system. To do this, we’ll create a new directory using the terminal and see it appear in your file explorer.

  1. Use your terminal to create a new directory.

    In your terminal, run mkdir "projects" to create a new directory. The new directory should also show up in your file explorer window.

    Terminal window
    mkdir "projects"
    • Directory/
      • Directoryusers/
        • Directoryboba-tan/
          • Directoryprojects/
    As you can see, the quotes are not part of the directory name.
  2. Find the new directory in your file explorer window.

    Look at your file explorer window (the one opened at the same position as your terminal) and see if you can spot the directory you just created.

Let’s enter the new directory we just created and confirm that everything looks as expected!

  1. Navigate to the new directory in your terminal.

    In your terminal, run cd "projects" to navigate into the new directory.

    Terminal window
    cd "projects"

    This will move your current position to the projects/ directory.

    • Directory/
      • Directoryusers/
        • Directoryboba-tan/
          • Directoryprojects/ <= You are here
  2. Confirm you entered the directory with your terminal.

    In your terminal, run pwd to find your current position.

    Terminal window
    pwd
    /users/boba-tan/projects
  3. Confirm that the directory is empty.

    In your terminal, run ls to show the files and directories at the current position.

    Terminal window
    ls

    ls should have no output, indicating that the directory you just created is empty.

Let’s do the reverse exercise: creating a “subdirectory” (inner directory) in your explorer window and witnessing it magically appear in your terminal.

  1. Enter the projects/ directory with your file explorer.

    In your file explorer, double-click on your “projects” directory to enter it.

    • Directory/
      • Directoryusers/
        • Directoryboba-tan/
          • Directoryprojects/ <= You are here
  2. Create a new directory with your file explorer.

    In your file explorer, create a new directory called “project1”. This will create a new project1 subdirectory inside projects.

    • Directory/
      • DirectoryUsers
        • Directoryboba-tan/
          • Directoryprojects
            • Directoryproject1/
  3. See the new directory in the terminal.

    In your terminal, run ls. The project1 directory has now appeared!

    Terminal window
    ls
    project1

We know how to enter a directory, but what about going back to a previous one? In this step, we’ll do just that: move one step up, back to our initial starting point.

  1. Remember where you currently are in your terminal.

    In your terminal, run pwd to check your current position.

    Terminal window
    pwd
    /users/boba-tan/projects
  2. Move your terminal to the containing (parent) directory.

    In your terminal, run cd ...

    Terminal window
    cd ..
    • Directory/
      • DirectoryUsers
        • Directoryboba-tan/ <= You are now here
          • Directoryprojects/
            • Directoryproject1/
  3. Confirm your position.

    In your terminal, run pwd and compare it to your previous output. The very last directory in the path should now be missing, indicating you moved one step up in the tree.

    Terminal window
    pwd
    /users/boba-tan

Let’s jump into the deep end and cross two directories with the same command! After this, we’ll use the “home address” shorthand (~) to go back to our home directory. This way, if you’re ever lost, you’ll always know your way back home.

  1. Enter the project1 directory.

    In your terminal, run cd projects/project1.

    Terminal window
    cd projects/project1

    This will move you from your current directory (/users/boba-tan) to the project1/ directory inside projects/.

    • Directory/
      • DirectoryUsers
        • Directoryboba-tan/
          • Directoryprojects
            • Directoryproject1/ <= You are here!
  2. Confirm your position.

    In your terminal, run pwd to confirm you’re in the right place.

    Terminal window
    pwd
    /users/boba-tan/projects/project1
  3. Jump back to your home directory.

    In your terminal, run cd ~.

    Terminal window
    cd ~

    This will move you from your current directory (the project1/ directory inside projects/) to your home directory, /users/boba-tan.

    • Directory/
      • DirectoryUsers
        • Directoryboba-tan/ <= You are here!
          • Directoryprojects
            • Directoryproject1/
  4. Visually confirm your position.

    In your terminal, run ls to see a list of the files in your home directory. Navigate to your home directory with your file explorer to confirm the files remain the same—projects directory included!

    Terminal window
    ls
    Blorbos Coding Documents
    FujoGuide Manga projects
    WebbedSite
  5. In your terminal, run pwd to confirm you’re in your home directory.

    Terminal window
    pwd
    /users/boba-tan

With this, you’re done! Don’t forget to delete the projects directory. And if you wish to clean up your messy terminal, try running the clear command!

Now that you have the basic tools in hand, you can start using your terminal more regularly. Good luck, and remember: these guides will be here for you any time you need them!