Exercise 0.2: Navigating Your File System
Moving Around with the cd Command
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
cdcommand 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.
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
- Examples:
- 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)
- Examples:
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:
cd ~(Go home)pwd(Confirm you are home)cd Documents(Move to Documents, using a relative path)pwd(Confirm you are in Documents)cd ..(Move up to the parent, which is home)pwd(Confirm you are home again)
Reflect and Review
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?