Topic 03

Just Enough Terminal

Hands-on

Programs are started from a terminal: a window where you type commands instead of clicking on things. Most people have never opened one on purpose, and it can look unfriendly, a dark box with a blinking cursor and no buttons. The good news is that this book needs only four things from it: open it, see where you are, move between folders, and run a command.

Think of it as giving directions over the phone instead of pointing at a map. At first it is slower than clicking. But it is exact every time, it can be repeated word for word, and it works in places where there is nothing to click. Every tool a programmer uses, Python included, starts from here.

What the Terminal Is

A terminal is a text conversation with your computer. You type a command, press Enter, and the computer answers in text. Then it waits for the next command. There is no hidden magic: each command is just the name of a program, followed by whatever you want to give it.

At every moment the terminal is standing inside one folder, called the current folder (you will also see it called the working directory). It is the same idea as an open window in your file manager: the folder you are looking at right now. Commands work in that folder unless you tell them otherwise.

Opening One

On Windows, open the Start menu, type Terminal, and choose Terminal. It opens PowerShell, the standard Windows command line. On a Mac, press Command and Space to open Spotlight, type Terminal, and press Enter.

Either way, you see a line ending in a symbol, usually a greater-than sign on Windows or a percent sign on a Mac, followed by a blinking cursor. That line is the prompt. It is the terminal saying: I am ready, type a command. On Windows the prompt also shows the current folder; on a Mac it shows the folder's short name.

Where Am I, and What Is Here?

Two commands answer those questions, and both work on Windows and on a Mac. The first is pwd, short for print working directory. It prints the full path of the current folder. When a terminal first opens, that is your home folder, the one with your user name.

Where am I? (Windows, PowerShell)
PS C:\Users\you> pwd

Path
----
C:\Users\you
Where am I? (macOS, Terminal)
you@mac ~ % pwd
/Users/you

Windows prints the answer under a small heading and uses backslashes between folder names; a Mac prints the bare path with forward slashes. Different punctuation, same meaning: your home folder.

The second command is ls, which lists what is in the current folder. You will recognise the names: Desktop, Documents, Downloads. They are the same folders you see in your file manager, just shown as text. On Windows the list comes as a table with dates and sizes; on a Mac it is just the names.

Moving Around

To step into a folder, type cd followed by its name. The letters stand for change directory. To go back up one level, type cd followed by a space and two dots. Two dots always mean the folder that contains this one.

Now make the folder this book works in. The command mkdir, short for make directory, creates a new folder in the current one. From your home folder, type the two commands below. The first creates a folder named python-course; the second steps into it. Run pwd afterwards and you will see the new folder at the end of the path.

Make the course folder and move into it (Windows and macOS)
mkdir python-course
cd python-course

One habit will save you a great deal of typing and many typos: the Tab key. Type the first few letters of a folder name and press Tab, and the terminal completes the rest for you. If several names start with those letters, PowerShell fills in the first one and each further Tab moves to the next; a Mac terminal fills in as much as the names share and shows you the choices. If nothing happens at all, no name starts with those letters.

The same move, two ways
Clicking
Open your home folder, then double-click python-course.
Typing
cd python-course, then pwd to check where you are.

Running a Command

Everything you type at the prompt has the same shape: the name of a program, then whatever you want to give it, separated by spaces. The cd command is a program name, and python-course is what you gave it. In the next topic, the first command you run will be the Python program itself, asked to report its version. From then on, running your own programs will look exactly the same.

A last reassurance. The commands on this page only look and move, apart from creating one empty folder. Nothing in this book asks you to delete anything from the terminal. If you make a typo, the worst that happens is a message saying the command was not recognised, and a fresh prompt waiting for you to try again.

Common Confusions
  • "One wrong command can break the computer." The commands in this book only look and move. A mistyped command produces a message, not damage.
  • "The terminal and Python are the same thing." The terminal is where you start programs. Python is one of the programs it can start, and you will install it in the next topic.
  • "I have to type every folder name in full." Tab completes names for you. Spelling still matters, but you rarely type a whole name yourself.
  • "The terminal can see every file on my computer at once." It works in one current folder at a time, just like an open file-manager window. When a file cannot be found, check which folder you are in first.
Why It Matters
  • "Which folder am I in?" is behind a large share of beginner errors later in this book. Running pwd first is a habit that pays for itself.
  • Every tool a programmer uses, from Python itself to package installers and test runners, starts from this window.

Knowledge Check

What is the terminal's current folder?

  • Every folder on the computer, which the terminal searches at once
  • The one folder the terminal is standing in, where commands work
  • A special hidden folder that only the terminal is allowed to use
  • The folder where Python is installed, which never changes

Which command shows the full path of the folder you are in?

  • ls, which lists the names of everything
  • cd, followed by the name of the folder
  • pwd, short for print working directory
  • mkdir, short for make a new directory

How do you move up one level, to the folder that contains the current one?

  • Type up and press Enter at the prompt
  • Close the terminal window and open it again
  • Type pwd twice so it moves you back one level
  • Type cd, a space, and then two dots

You type the first few letters of a folder name and press Tab. What happens?

  • The terminal completes the name if exactly one folder matches it
  • The terminal runs the command straight away without asking you
  • A new folder is created with the letters you have typed so far
  • The letters are deleted so that you can start typing the name again

You got correct