16.4. Navigating the Terminal Window¶
Moving from a GUI to a CLI can be tricky because we are used to dragging our files from one folder to another. The first skill we need to practice is how to figure out where we are in the filesystem!
On the previous page, we used pwd
to print the path to our current
directory. However, we can also find clues inside the terminal prompt:
Mac
device_name:directory_name username$
Windows
username@device_name MINGW64 path$
directory_name
and path
tell us our location in the system. As we enter
commands, device_name
and username
stay the same. However, path
and
directory_name
change.
Note
In the remaining terminal examples, we will just display the $
symbol
from the prompt.
16.4.1. Moving Between Directories¶
We often need to move between directories in the file system. The command
cd
(for change directory) allows us to do this. The general syntax is:
cd new_directory
new_directory
is the path for where we want to be. We do NOT need to
indicate our current location.
Example
Let’s assume we want to move from our current location in the file tree
(Photos
) to Chemistry
.
The terminal command to make this move appears on line 3:
1 2 3 4 5 | $ pwd
/MyLaptop/Photos
$ cd /MyLaptop/School/Chemistry
$ pwd
/MyLaptop/School/Chemistry
|
In this case, we included pwd
to show our starting and ending locations.
However, these commands were not necessary for the move.
16.4.1.1. Navigation Shortcuts¶
When moving through a file tree, we often only need to move up or down one level. For quick changes like this, we don’t need to type out a full path.
Examples
Let’s say we want to move up one level from Chemistry
to School
.
Instead of typing out the entire absolute path, we can use a terminal
shortcut!
1 2 3 4 5 | $ pwd
/MyLaptop/School/Chemistry
$ cd ..
$ pwd
/MyLaptop/School
|
The cd ..
shortcut tells the terminal, From the current directory, move
up one level.
To move down one level from a parent directory into a subdirectory, the
path syntax is ./directory_name
.
1 2 3 4 5 | $ pwd
/MyLaptop/School
$ cd ./LCHS
$ pwd
/MyLaptop/School/LCHS
|
The .
represents the path to the current directory. In this case, it
stands for /MyLaptop/School
. The command on line 3 tells the terminal,
From the current directory, move into the LCHS subdirectory.
The ..
and .
shortcuts can also be part of a longer path. For example,
cd ../..
moves us up two levels from our current directory, while
cd ./directory_name/other_directory_name
moves us down two levels.
16.4.2. Feedback¶
Another big difference between a GUI and a CLI involves the amount of feedback we receive. With a GUI, we can see when we move, create, or delete a file. An icon appears, moves, or disappears as we perform the action. Sometimes a window even pops up to give us more information.
The terminal rarely displays an output to let us know when a change occurs. We need to keep an eye on the prompt and be more deliberate about checking the results of our commands.
16.4.3. Check Your Understanding¶
Use this file tree to help answer the following questions:
Question
Assume we start in the Homework
directory. In the terminal, we execute
the following command:
$ cd ../..
What is the path to our new location in the filesystem?
- /MyLaptop/School/LCHS/Homework
- /MyLaptop/School/LCHS
- /MyLaptop/School
- /MyLaptop
Question
Which TWO of the following terminal commands gets us from Homework
to
Misc Docs
?
- cd /MyLaptop/Desktop/MiscDocs
- cd /LCHS/School/MyLaptop/Desktop/MiscDocs
- cd ../../../Desktop/MiscDocs
- cd ./Desktop/MiscDocs