← The command line

Where files live

Files live in a tree of folders, and a path names a place in it. pwd says where you are, ls lists what is here and cd moves you, with full paths from the top (/), short paths from where you are, .. for the folder above and ~ for home.

Most of the world's servers have no mouse and no windows. People run them by typing. Where do you even start?

A shell is a way to use a computer by typing. You type a command, press Enter, and the computer answers. This board is a pretend computer, so nothing you type can break anything.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Where will you be?

You are in /home/sam. You type cd projects, then pwd. What does pwd show?

TryTry it on the board and compare the result with your prediction.

Try: find your way

Was your prediction right? Type pwd to check.

Try it yourselfYour edits are saved in this browser.

Get to the game folder. Type ls to look around and cd to move; the tree shows where you are.

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: reading a path

Worked exampleBefore each step, say what you think comes next.
  1. /home/sam/projects/game/home/sam/projects/gameA full path starts with /, the very top, and works from anywhere.

Now try two lots of ..

You are in /home/sam/projects/game. You type cd ../.. Where are you now?

Sam explains what cd does. Click the line where it first goes wrong.

Which command lists what is in the folder you are in?

ModifyChange the problem on purpose and see what happens.

Vary: other ways to move

Try it yourselfYour edits are saved in this browser.

Go to the folder /etc with one cd, using a full path.

Use the board. This ticks when you get there.

You start in projects/game. Get to the photos folder using ..

Use the board. This ticks when you get there.

You start in /etc. Get home with the shortest command you can.

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Paths

Which path works from any folder?

The prompt says sam@school:~/projects$. Where are you?

Review: the same ls command works on an SSD, a USB stick or a network drive. Why?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Find and read a file

Then: what's the full path of that file? Could you print it with one command from home?

Try it yourselfYour edits are saved in this browser.
Need a hint?

No tree this time: use ls to look inside each folder.

Another hint

It's somewhere inside projects.

Another hint

cd projects/game, then cat level1.txt.

There's a file called level1.txt somewhere in your home folder. Find it and print it with cat.

Use the board. This ticks when you get there.

For teachers

Students move around a pretend Linux filesystem with pwd, ls and cd, reading full paths, short paths, .. and ~, with a folder tree beside the terminal (AC9TDI10K01 node 1, the operating system's file system). About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the boards yourself. Everything runs in the browser on a pretend computer; nothing touches the school's machines.

The one idea: files live in a tree, and a path names a place in it. The folder tree is on for the Try and Vary and off for the Make, so students build the path themselves.

For the real thing (optional, after the course): a Raspberry Pi is best; WebVM runs Linux in a browser tab with no install (test it on the school network first); Mac Terminal works with the same commands; WSL or VirtualBox on Windows need admin rights.

Running the lesson

  1. Predict: students who said /projects think cd starts from the top.
  2. Try: ask what the prompt shows after each cd.
  3. Worked example: model reading a path aloud: "from the top, home, sam, projects".
  4. Vary: ask which way works from anywhere.
  5. Make: no tree: ask how they knew where to go.

The hard part (on purpose)

The first minutes at a prompt feel like guessing. Let students type and get it wrong: the board is pretend, errors are friendly, and the tree shows where they are.

When students get stuck

Stretch and support

Stretch: Press Tab after typing the start of a folder name. What does it do? (It completes the name.)

Support: A card with four commands: pwd (where am I?), ls (what's here?), cd name (go in), cd .. (go up).

Where it leads

Next: Reading and finding (cat, grep, hidden files).

Links: Security and privacy › What the operating system does.

What each step is for

Now you can
Next lesson2. Reading and findingcat prints a whole file and grep prints only the lines that contain a word. Names that start with a dot are hidden: ls skips them, ls -a shows them. With these you can find anything on a computer you can't see.