How Your Computer Thinks: Command Line Essentials
Before You Start
You should know: - That computers use a hierarchical system to store files (folders inside folders).
You will learn: - How to open a terminal on Mac, Windows, and Linux. - How to navigate your computer’s file system without a mouse. - Practical shortcuts: tab completion, the home directory, and handling spaces in names. - Why the command line is the foundation of local scientific computing.
Introduction
In the previous chapter, you wrote Python code in a browser. That was a great sandbox, but real scientific computing happens locally — on your own machine, reading your own files, processing your own satellite imagery or datasets.
However, Python running locally is essentially blind. It doesn’t know where your files are stored. If you tell Python to open temperature_data.csv, it looks only in the exact folder it is currently standing in. If it can’t find it there, it throws an error.
To control Python, you must first learn to control your computer the way a programmer does: through the command line. The command line is a text-based interface for talking directly to your operating system. It has many names — terminal, console, shell, PowerShell, command prompt — but they all do the same fundamental job.
Opening a Terminal
The first step is knowing how to get there.
On macOS: Press Cmd + Space to open Spotlight Search. Type Terminal and press Enter. The Terminal app opens — a window with a blinking cursor waiting for input.
On Windows: Press the Windows key, type PowerShell, and press Enter. Windows PowerShell is the modern command-line environment and understands most of the same commands as macOS and Linux terminals.
(Older tutorials may tell you to use Command Prompt, cmd.exe. PowerShell is better; use it instead.)
On Linux (Ubuntu/Debian): Press Ctrl + Alt + T. A terminal window opens immediately.
The Mental Model: You Are Always “Somewhere”
When you use a mouse, you open a Finder or File Explorer window and browse inside folders visually. In the terminal, you don’t browse — you step inside a specific folder and all your commands run from there.
Imagine your hard drive as a building with thousands of rooms. The terminal is you, standing in one specific room at a time. This room is called your working directory.
1. Where am I? (pwd)
The first command to learn is pwd — Print Working Directory. It tells you exactly which room you are currently standing in.
In your terminal, type and press Enter:
pwdYour computer replies with something like:
/Users/sarah ← macOS / Linux
C:\Users\sarah ← Windows
This is your home directory — the room you start in every time you open a new terminal. The home directory is so common that it has its own shorthand symbol: ~ (tilde). Anywhere you could type the full path, you can type ~ instead. This is useful for writing paths that work on any computer.
2. What is in this room? (ls)
Now see what is in the folder you are standing in:
ls(On Windows PowerShell, ls works. On older Command Prompt, use dir.)
Your terminal lists every file and folder in the current directory. You should see familiar names like Desktop, Documents, and Downloads.
Add the -l flag for a detailed view (file sizes, dates, permissions):
ls -l3. Create a new folder (mkdir)
Let’s create a dedicated folder for your computing work:
mkdir coding_projectsmkdir stands for Make Directory. If it succeeds, your terminal returns a blank cursor — silence means success. Run ls again and you will see coding_projects in the list.
Spaces in folder names cause problems. If you type mkdir my projects, the shell interprets this as two separate names and creates two folders: my and projects. Use underscores (coding_projects) or hyphens (coding-projects) instead. If you must use a space, wrap the entire name in quotes: mkdir "my projects".
4. Step into a folder (cd)
You have created the folder, but pwd still shows you standing outside it. Use cd — Change Directory — to step inside:
cd coding_projectsRun pwd again. Your location now ends in coding_projects. Run ls — nothing there yet, because this folder is empty.
5. Step back out (cd ..)
To step backward into the parent folder, use two dots:
cd ..The .. always means “the folder immediately above this one.” Run pwd to confirm you are back where you started.
To jump straight to your home directory from anywhere:
cd ~To jump to a specific path in one command:
cd ~/coding_projects/flood_analysisTab Completion: Your Fastest Typing Shortcut
Typing long folder names is slow and error-prone. Every terminal supports tab completion — press Tab after typing a few characters of a name and the terminal fills in the rest.
cd cod[Tab]If there is only one folder that starts with cod, it completes to coding_projects instantly. If there are multiple matches, press Tab twice and the terminal lists the options.
Use tab completion constantly. It avoids typos, confirms the name you think exists actually exists, and is far faster than typing.
The Home Directory Shortcut
~ is not just a shortcut for the prompt — it works in any path:
ls ~/Documents
cd ~/coding_projects/flood_analysisThis means you can write paths that work correctly regardless of which directory you are currently in, and regardless of whose computer the script runs on (since every user’s home directory is ~).
Why This Matters for Geographic Data
Imagine you download a 5 GB LiDAR dataset to your Downloads folder. Your Python analysis script is saved on your Desktop. You open a terminal, cd Desktop, and run the script. Python wakes up standing on the Desktop. Your script says “open the LiDAR file” — Python looks on the Desktop, finds nothing, and crashes with FileNotFoundError.
Understanding the working directory means you always know exactly where Python is looking for files. You will use cd to navigate to your data, and you will organize your projects so that your code and data live in the same folder (or you use explicit paths to tell Python exactly where to look).
Verify Your Work
Work through each of these steps before moving on:
- Open your terminal using the method for your operating system.
- Run
pwdto confirm your starting location. - Run
lsto see the contents of your home directory. - Run
mkdir geography_workspaceto create a new folder. - Run
cd geography_workspaceto step inside it. - Run
pwdto confirm your path changed. - Run
cd ..to step back out. - Practice using Tab to complete a folder name in your home directory.
If you can confidently do all of these, you are ready to install Python on your machine.
Next Steps
- Proceed to Installing Python