cd, relative & absolute paths

Move between folders

Lesson 2 of 20 · 8 min · Module 1: Find your way around

Working in the right folder saves typing. The cd command (change directory) moves you around the filesystem.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Change folders with cd
  • Tell relative paths from absolute paths
  • Use .., ~, and - as shortcuts

The idea

cd projects moves into a folder inside the current one: a relative path. cd /etc uses an absolute path from the root. cd .. goes up one level, cd ~ (or plain cd) returns home, and cd - jumps back to the previous folder.

cd projects/website
pwd
cd ../..
pwd

01Relative paths start from where you are

cd projects/website works because projects is inside your current folder. The same command from /etc would fail, because /etc has no projects folder.

02Two dots mean "one level up"

Every folder contains a special entry .. that points to its parent. cd ../.. climbs two levels at once. A single dot . means the current folder.

cd projects/website
cd ..
pwd
Output
/home/learner/projects

03Absolute paths work from anywhere

A path starting with / never depends on your current folder. cd /var/log takes you to the system logs from any location. cd ~/logs is also absolute, because ~ expands to /home/learner.

Your turn

Move into projects/website and print the folder with pwd. Then use .. to go back up to your home folder, and finish inside logs.

What the checks look for

  • Visits /home/learner/projects/website
  • Uses .. to go up
  • Finishes inside ~/logs
Try it in the editor →

Take this with you

A relative path depends on where you are; an absolute path does not.

Go a little further

Try cd - twice and watch it switch between your last two folders.

Learn Linux Command Line for free

20 short lessons with real code and instant checks.

See the whole course →