Skip to content

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.

Lesson 2 of 166 minSkip to the 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, then projects/website means the same place.

A few names are special:

NameMeans
.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 projects
cd website/css
pwd
cd ..
cd /var/log
cd

cd .. 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.

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 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)

Lesson 2 of 16.

learner@sandbox: ~bash (practice)
Note: Practice shell for this lesson. Type a command and press Enter (help lists them all).