Moving Around
A path is a line of names that leads to one directory. A path can start at the top or start where you are.
Move by absolute path
Cd moves to the practice directory.
$ cd ~/practice
$ pwdMove by relative path
Cd moves down into the notes directory.
$ cd ~/practice
$ cd notes
$ pwdMove to the parent
Cd .. moves up to the parent directory.
$ cd ~/practice/notes
$ cd ..
$ pwdMove to the root
Cd / moves to the root directory.
$ cd /
$ pwdExample
$ cd ~/practice/projects/website
$ pwd
$ cd ../..
$ pwdKey points
- A path names each step on the way to one directory.
- An absolute path starts at the root directory, like /home/hatch/practice.
- A relative path starts where you are, like notes.
- The root directory is the top directory, and its name is a single slash.
- A parent directory is the directory above the current directory.
- Use cd to move to a new directory.
- Use cd .. to move to the parent directory.
- Use cd / to move to the root directory.
In this example, four lines move twice. The first line moves to the website directory. The second line prints its name. The third line moves up two steps. The fourth line prints the practice directory.
Note
A relative path means something different in each directory, so notes works only below the practice directory.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does cd .. do?