Level 0 · Base Camp

The Terminal, Files and Paths ⌨️

The black window with the blinking cursor is not a hacker thing. It is a text conversation with your computer, and it is about to become the room you live in.

Why bother, when you have a mouse

Clicking is great for one file. It is terrible for four thousand. The terminal is how you say "rename every photo in this folder" in one sentence instead of four thousand drags. It is also the only sane way to run Python programs, install packages, and use almost every professional development tool ever built.

More importantly: it is a text interface, which means every instruction in every tutorial you will ever read is a line you can copy. Nobody can screenshot a mouse gesture.

HALF LIGHT[Easy: Failure]

It looks like the interface from a film where someone says 'I'm in'. You are going to type something wrong and destroy the machine.

You are not. You would have to go well out of your way. The commands in this lesson look at things and move you around; not one of them deletes anything.

Opening it

SystemHowWhat you get
macOSCmd+Space, type 'Terminal', Enterzsh, a Unix shell
WindowsStart menu, type 'PowerShell', EnterPowerShell
LinuxCtrl+Alt+T, usuallybash or zsh

You will see a prompt: some text, then a cursor. It is telling you where you are and waiting. You type a command, press Enter, it does the thing, and gives the prompt back.

Where am I? The idea of a path

Your files live in a tree. A path is the route from somewhere to a specific file, written as folder names joined by slashes:

/Users/you/Documents/python/hello.py     macOS and Linux
C:\Users\you\Documents\python\hello.py     Windows (backslashes)

Two kinds of path, and the difference causes more beginner pain than any other topic:

Two special names you will use constantly:

WrittenMeans
.the folder I am in right now
..the folder one level up
~my home folder (macOS/Linux, and PowerShell understands it too)
🪤 The number one beginner error

python hello.py failing with can't open file 'hello.py': No such file or directory almost never means the file is missing. It means you are not standing in the folder that contains it. Run ls (or dir on Windows) and look. If the file is not in that list, you need to cd somewhere else first.

The ten commands that cover almost everything

macOS / LinuxWindows PowerShellWhat it does
pwdpwdPrint working directory: where am I?
lsls or dirList what is in this folder
ls -lals -ForceList everything, including hidden files
cd foldercd folderGo into a folder
cd ..cd ..Go up one level
cd ~cd ~Go home
mkdir namemkdir nameMake a folder
cat filecat filePrint a file to the screen
python3 file.pypython file.pyRun a Python program
clearclsWipe the screen (nothing is deleted)

A first session, annotated

~ $ pwd
/Users/you

~ $ mkdir python-school
~ $ cd python-school
~/python-school $ pwd
/Users/you/python-school

~/python-school $ ls
(nothing here yet, which is correct)

~/python-school $ cd ..
~ $ 

That is the whole loop: look around, move, make something, look again. You now know enough terminal to finish this entire course.

Three tricks that will save you hours

SAVOIR FAIRE[Medium: Success]

Watch an experienced developer's hands sometime. They barely type full paths. It is all Tab, up arrow, Ctrl+R, muscle memory built over years. None of it is talent. It is just the same six keys, ten thousand times.

Dragging beats typing

Nobody types long paths. On macOS and Linux, type cd (with the space) and then drag the folder from your file manager onto the terminal window. The path appears. Press Enter. On Windows, hold Shift, right-click a folder, and choose "Copy as path", then paste.

Exercise 1

Find your feet

Open a terminal and run these, in order. Read each result before typing the next one.

pwd
ls
cd ~
mkdir python-school
cd python-school
pwd
Reveal solution

You should end with a path ending in /python-school (or \python-school on Windows). That folder is where everything in this course will live.

If mkdir said the folder already exists, no harm done: you have run it twice, which is exactly as damaging as it sounds.

Exercise 2

Read a path

You are in /Users/you/python-school. Where do these point?

  1. notes.txt
  2. ../Downloads/data.csv
  3. /etc/hosts
Reveal solution
  1. /Users/you/python-school/notes.txt, in the folder you are standing in.
  2. /Users/you/Downloads/data.csv: up one level, then down into Downloads.
  3. /etc/hosts exactly, because it starts with a slash. Absolute paths ignore where you are standing.
+100 XP