Where you are, and files

INPUT · Slides

Where am I?

01 / 09

What is the command line?

When you handle files on a computer or a phone, you tap a picture of a folder to open it. The command line is the same thing, only you say it in words.

There are no pictures, which makes it feel standoffish at first, but you get something in return. What you did stays behind as text, so you can hand it to somebody as it is, and you can have it run on its own. That is why it is still in daily use where software gets made.

What you can see at the bottom of this screen is a real Linux, running inside your browser. Nothing you type leaves this terminal.

02 / 09

Reading the prompt

Open a terminal and you get one line like this.

This is called the prompt. The ~ on the left is where you are, and the $ is its way of saying "go ahead, type something".

It looks like there is nothing there, but the most useful thing on the screen is written right here. When you get lost, read the prompt first.

~ $

03 / 09

pwd — say where you are

When the ~ in the prompt is not enough, type pwd. It tells you where you are, spelled out in full.

It stands for print working directory.

~ $ pwd

Result

/home/learner

04 / 09

A directory is a folder

A place like /home/learner is called a directory in Linux. It is the same thing you normally call a folder.

Read it left to right, split on /, going from the bigger container to the smaller one. /home/learner means the learner box inside the home box.

The / at the very left is the way in to everything. There is nothing above it.

05 / 09

ls — see what is there

Type ls and it lays out what is in the place you are standing. Short for list.

Leave a space after a command and add a word, and you change what it does. ls -l gives you one thing per line with the details attached. An extra like -l is called an option.

~ $ lsdiary  memo.txt  photos

06 / 09

cd — go inside

To move into a box, use cd. Short for change directory.

You can see whether it worked because the left of the prompt changes. cd shows nothing at all, but that is not a failure — it is just that it stays quiet when things go well.

A lot of Linux commands say nothing when they succeed. Worth knowing, so you stop worrying about it.

~ $ cd diary~/diary $

07 / 09

.. goes up one, cd on its own goes home

To come back out, type cd ... .. is the fixed way of writing the box one level up.

However deep you have gone, typing just cd puts you straight back home. Lost? Type cd. That might be the single most useful thing in this chapter.

~/diary $ cd ..~ $

08 / 09

Relative and absolute paths

There are two ways to write a place.

  • Relative path: written from where you are standing. Things like diary or ../photos, which do not start with /
  • Absolute path: written from /, spelled out in full. Something like /home/learner/diary, which points at the same place wherever you are

Relative when you want to type less, absolute when you want to be sure. That is the whole difference.

~/photos $ cd /home/learner/diary~/diary $

09 / 09

Now have a go

From here you type into the terminal yourself.

Awkward symbols can be tapped in from the bar above the keyboard, and common commands can be dropped in from the buttons below. You do not have to type all of it with your fingers.

Marking looks at what happened, not at what you typed. cd diary or cd ./diary — if you got there, you got it right. There is no one way you have to write it.