Moving around: cd, paths, . and ..
Learn to move between directories with cd, read absolute and relative paths, and use ., .., ~ and cd - in a live practice terminal.
Files live in directories (folders), and directories live inside other directories, all the way up to the top one, called root and written /. You are always in one directory: the working directory. Commands look for names there unless you tell them otherwise.
Paths
A path says where something is.
- An absolute path starts with
/and works from anywhere:/home/learner/projects/website. - A relative path starts from where you are: if you're in
/home/learner, thenprojects/websitemeans the same place.
A few names are special:
| Name | Means |
|---|---|
. | this directory |
.. | the directory one level up (the parent) |
~ | your home directory, /home/learner |
Changing directory
cd (change directory) moves you. The prompt changes to show where you are now:
cd projectscd website/csspwdcd ..cd /var/logcdcd .. goes up one level and cd ../.. goes up two. cd on its own always takes you home, and cd - jumps back to the directory you were in before.
Tip:Press Tab while typing a name and the shell finishes it for you. It saves typing and typos, and if nothing happens, the name you started doesn't exist where you are.
Your turn
Go into ~/projects/website/css. Then, using .., move up to ~/projects (two levels up).
Your task
Go into ~/projects/website/css. Then, using .., move up to ~/projects (two levels up).
- Get into ~/projects/website/css (not done yet)
- Use .. to move up to ~/projects (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
cd- Change the current directory More on cd →
pwd- Print the current (working) directory