What a terminal is
Soon you will install some tools by typing commands into a window called a terminal. Before that, this page explains what that window is, where it came from, and why programmers still choose it. At the end you will find the terminal on your own computer and run your first commands there.
Here is a taste first. The black box below is a practice terminal. It runs in your browser and is not connected to your computer, so nothing you type can change or break your files. Click it, type a command and press Enter. The text before your cursor is the prompt, which says the terminal is ready.
Type pwd and press Enter. It prints the folder you are in. Then type ls and
press Enter. It lists what is inside that folder.
✓ Done. You reached the goal.
Hint 1
Type the letters pwd, press Enter, then do the same with ls.
You just asked the computer two questions in words and it answered in words. The rest of this page explains what that window is and why programmers use it.
Where terminals came from
The first computers had no screen and no keyboard. People gave them instructions by flipping physical switches and plugging cables into panels. A program could take hours to enter, and one wrong switch meant starting again.
Later, people punched holes in cards and paper tape to carry instructions, and fed the cards into the machine. You handed over a stack of cards and came back later for a printout of the result.
In the 1960s computers got faster, and many people wanted to use one machine at the same time. The answer was to give each person a terminal: a keyboard and a printer (later a screen) on a desk, connected by a wire to the big computer in another room. It was called a terminal because it sat at the end of the wire, where the person was. You typed a line, pressed Enter, and the computer typed its answer back. The first terminals printed on paper. By the late 1970s, models such as the DEC VT100 used a screen instead, with glowing letters on a dark background.
That is the black screen with green or white text you have seen in films. Hacker scenes in movies such as WarGames (1983) and The Matrix Reloaded (2003) show people typing commands into a terminal. The films exaggerate what the commands can do, but the screen itself is real.
Why computers started to look different
For years, text was the only way to talk to a computer. Then researchers found a way to show the computer's contents as pictures. In the 1970s, a research lab at Xerox built a computer with windows, icons and a mouse. Apple's Macintosh (1984) and Microsoft Windows (1985) brought that idea to ordinary homes.
These designs borrowed things people already knew from an office: a desktop, documents, folders and a trash can. You did not need to remember any words. You looked at the screen, found the picture of the thing you wanted and clicked it. That made computers usable by almost everyone, and it is why your computer looks the way it does now.
Why programmers still use the terminal
Pictures are friendly, but they have limits. A graphical screen only offers what its designers decided to put on it. You click what you can see, and the same job can take a different number of clicks on a different computer.
Take one small job: make a new folder called notes.
With a mouse, the steps depend on the computer. On a Mac you open Finder, find the right window, then choose File, New Folder (or right-click and choose it). On Windows you open File Explorer, right-click an empty spot, and choose New, then Folder. Either way the computer first makes a folder with a stand-in name (Finder calls it "untitled folder"; File Explorer calls it "New folder"), and you then have to rename it. You also have to be looking at the right window, or the folder lands in the wrong place.
In a terminal, you type one line:
~/python-projects % mkdir notes
Read it as a sentence. mkdir is short for "make directory" (a directory is
another word for a folder), so it means "make a folder". notes is the name to
give it. Put together, the line says: make a folder named notes. It goes in
the folder the terminal is currently in, and it has the name you typed from the
start. (The ~/python-projects % at the start is the prompt, which comes up
again below. You do not type it.)
| Point and click | Terminal | |
|---|---|---|
| How you ask | Find a menu, a button or a right-click option | Type a short sentence |
| Steps | Several, and they differ between Mac and Windows | One line, the same on both |
| The name | A stand-in you rename afterward | Chosen in the command |
| Where it goes | Wherever the window happens to be | The current folder, stated by the prompt |
A command says exactly what you want, in words:
- It is precise.
mkdir notesmeans one thing: make a folder namednotes, here. Nobody has to guess which button you meant, and the computer does not have to guess either. - It can be repeated. You can save a list of commands in a file and run it again tomorrow, or on a hundred computers.
- It can be shared. You can send someone a command in a message. You cannot send someone "click the third menu, then the second option".
- It works without a screen full of pictures. Many computers that run websites and apps have no display at all. You reach them by typing.
A terminal is not better than clicking for everything. Dragging a photo into a folder is easier with a mouse. Programmers use both, and they pick the terminal when they need to be exact.
What is inside a terminal window
Today's terminal is a program that imitates those old machines, so it is sometimes called a terminal emulator. Two things work together in the window.
- The terminal shows text on the screen and passes your keystrokes along.
- The shell is a program that reads each line you type, works out which program you want, runs it, and prints the result. When people say "type this in the terminal", the shell is the one doing the work.
The shell shows a prompt to say it is ready for a command. It often ends in
%, $ or >, depending on the shell. Your command goes after it. Nothing
happens until you press Enter, so you can fix a typo first.
A command line has a simple shape: a command name, then anything extra the command needs, separated by spaces. The extras are called arguments.
~/python-projects % ls notes
Here ls is the command and notes is the argument, so the line lists what is
inside the notes folder. The shell splits the line at the spaces. The first
word is what to do, and the rest say what to do it to.
Some commands also take an option, a word starting with a dash that changes how the command works. Here is a longer line with every part labeled:
Find the terminal on your computer
The terminal on your own computer is the real one. The practice terminal above and those on the next page are a safe copy that lives in your browser, but the real one is the one you will use for the rest of the course. Open it now.
Mac. Press Cmd+Space, type Terminal and press Enter. You will see a prompt
ending in %. Apple has a guide to it:
Terminal User Guide for Mac.
Windows. The choice is yours. This course uses Linux and Mac style commands in its examples, and most software engineers use those commands too, so Git Bash is the easier path.
- Git Bash. It gives Windows the same style of terminal that Mac and Linux
have, so the examples work as written. Download Git for Windows from
git-scm.com/install/windows and run the
installer (the default choices are fine). Then press the Windows key, type
Git Bashand press Enter. The prompt ends in$. - PowerShell. It is already installed. Press the Windows key, type
PowerShelland press Enter. (Windows 11 may open an app called Windows Terminal instead. That works too.) The prompt ends in>. Some commands differ from the examples, and you will need to adjust them. Microsoft has a guide: Windows Terminal documentation.
Linux. Look for Terminal in your applications menu. On many systems
Ctrl+Alt+T opens it. The prompt usually ends in $. Ubuntu has a beginner
tutorial: The Linux command line for
beginners.
Run two commands
Type each command and press Enter. They only look around, so they cannot change anything. Your prompt will look different from the one shown here. Type only the command after it.
~/python-projects % pwd
pwd tells you which folder the terminal is in right now. On a Mac or Linux
computer it prints something like /Users/yourname. In Git Bash it prints a path
such as /c/Users/yourname. In PowerShell it prints a small table with a path
such as C:\Users\yourname.
~/python-projects % ls
ls lists the files and folders inside the folder you are in. They are the same
things you would see if you opened that folder in Finder or File Explorer. You
can open your file browser and compare.
If you saw output from both, you have used a real terminal. The next page explains these commands and a few more, and lets you practice in a terminal that cannot hurt anything.
Next: Find your way around the terminal.