Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Navigation Basics  ›  Lesson

pwd, ls and cd — Finding Your Way

Basic Commands 12 minpwd shows where you are, ls shows what is there, and cd moves you using absolute or relative paths.

pwd, ls and cd — Finding Your Way

You open a terminal and see only a blinking cursor. There are no windows or icons, so you can't glance at a desktop to see where you are. On the command line you ask, and three tiny commands do most of the asking. Throughout this course we'll follow Asha, who keeps her community garden's records in a folder called garden in her home directory.

The rule

Where am I, what is here, go there: pwd, ls, cd.

pwd (print working directory) tells you which folder the shell is "standing in" right now:

$ pwd
/home/asha

ls (list) shows what is inside the current folder, or inside any folder you name:

$ ls
garden  photos  todo.txt
$ ls garden
harvest.csv  notes.txt  plots

Two options you'll use every day:

  • ls -l gives the long listing, with permissions, owner, size and date on each line.
  • ls -a shows all entries, including hidden ones whose names start with a dot, such as .bashrc.

You can combine them: ls -la.

cd (change directory) moves you:

$ cd garden
$ pwd
/home/asha/garden

A path is written one of two ways:

  • Absolute paths start with / and describe the full route from the top of the system: /home/asha/garden.
  • Relative paths start from where you are now: garden, or plots.

A few special names work anywhere:

Name Means
. this directory
.. the parent directory, one level up
~ your home directory
- (with cd) the directory you were in before

A plain cd with nothing after it takes you home.

The shortcut

Before every cd, read the path's first character. A / means "start from the top". A ~ means "start from home". Anything else means "start from here", so you need to know where "here" is, which is what pwd tells you.

Asha goes from her plots to her photosStep 1 of 5
  1. Where am I?

    pwd prints /home/asha/garden/plots.

The common mistake is typing a relative path from the wrong place. cd plots only works if plots is directly inside your current directory. When a cd fails with "No such file or directory", run pwd and ls before you try again.

Drills

Answer fast — trust the rule.

quick drill

Asha is in /home/asha/garden. Which command prints that path?

quick drill

Which command shows hidden files such as .bashrc as well as the normal ones?

quick drill

Asha is in /home/asha/garden/plots. Where does cd .. take her?

quick drill

Which of these paths means the same place no matter where you run cd?

quick drill

Asha runs cd /etc, then cd ~/garden, then cd -. Where is she now?

Remember

  • pwd says where you are, ls shows what's there, cd moves you.
  • Read the first character of a path: / starts at the top, ~ starts at home, anything else starts from here.
  • If a cd fails, check where you are with pwd and ls before guessing again.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPlan a route

Asha is in /home/asha/garden/plots and wants to get to /home/asha/photos. Give one relative and one absolute cd command that work, and explain how you can tell which kind of path each one is.