Index Ai Academy
Phase 0 · Tools · Developer tools

The terminal

Navigate folders and run programs by typing commands.

About 25 minutes · Free lesson

Start this lesson

Why it matters

Almost every AI tool starts in the terminal. Installing a library, running a script, starting a local model, copying a project from GitHub, even running coding assistants like Claude Code: the instructions are terminal commands. Once typing cd and ls feels normal, a page full of setup commands stops looking like a wall. It starts looking like a checklist.

What you'll be able to do

  • Find out where you are and move between folders with pwd, ls and cd
  • Create, read, copy, move and delete files from the command line
  • Run a Python script from the terminal
  • Read the setup instructions in an AI project's README without guessing

What it covers

  1. A text conversation with your computer
  2. Where am I?
  3. Making and changing files
  4. Running programs
  5. Reading a README's instructions
  6. Worked example: set up a report folder

A text conversation with your computer

The terminal is a window where you control your computer by typing commands instead of clicking. It's like texting your computer instead of pointing at things. On a Mac it's the Terminal app (Applications → Utilities → Terminal). On Windows, use PowerShell or Windows Terminal. The program inside it that reads and runs your commands is called the shell. On macOS it's zsh.

You type a command after the prompt and press Return. The shell runs it, prints any output, and shows a new prompt. A prompt often looks something like this:

sam@MacBook campaign-report %

That's your username, your computer's name, the folder you're in, and %, which means "ready". You never type the prompt itself.

Most commands follow the same shape:

  1. a program name,
  2. optional flags, which change how it behaves (they start with -),
  3. arguments, which say what to act on.
ls -l data

Here ls is the program (list files). -l is a flag (long format, with sizes and dates). And data is the argument (which folder to list).

Note: In documentation you'll often see commands written as $ ls -l. The $ stands for the prompt. Don't type it.

Where am I?

Your files are arranged as a tree of folders. The terminal also calls them directories. At any moment the shell has a current working directory: the folder your commands act on. It's like the room you're standing in. Three commands do most of the work of finding your way around:

CommandWhat it does
pwdprint working directory: shows the folder you're in
lslists what's in the current folder (ls data lists another folder)
cd namechange directory: moves into a folder
Quick check
You've lost track of which folder you're in. Which command tells you?
  1. mkdir
  2. pwd
  3. cd ..
  4. ls
Show the answer

pwd

pwd prints the working directory. ls lists what's in it, and cd moves you somewhere else.

A few shortcuts make cd fast:

  • cd .. moves up one level, to the folder that contains this one. .. always means "the parent folder", and . means "this folder".
  • cd ~, or just cd on its own, goes to your home folder, /Users/yourname. The ~ is shorthand for it.
  • cd ~/projects/campaign-report jumps straight to a folder from anywhere.

Paths come in two kinds, like a full street address versus "two doors down":

  • An absolute path starts at the top of the tree with /, or at your home folder with ~. It works from anywhere: /Users/sam/projects/campaign-report/notes.txt.
  • A relative path starts from wherever you are now. If you're already in campaign-report, the same file is just notes.txt, and the spending data is data/spend.csv.

Files whose names start with a dot, like .gitignore or .env, are hidden. Plain ls skips them, and ls -a shows them. You'll meet both of those files in later lessons, and both matter.

Tip: Press Tab to finish a file or folder name for you. Type cd da and press Tab, and the shell completes it to cd data/. It saves typing and catches typos.

Try it below. The terminal starts inside a small project folder.

Quick check
What does this print?
path = "/Users/ann/projects/shop"
parts = path.split("/")
print(parts[-1])
  1. /Users/ann
  2. projects
  3. shop
  4. Users
Show the answer

shop

split("/") cuts the path at each slash, and [-1] takes the last piece, shop. That last piece is the folder you're in, which is what the terminal prompt usually shows.

Try it now

Work through the tasks under the terminal, or type help to see every command the simulator knows.

Quick check
You're in ~/projects/campaign-report. You run cd data, then cd .., then pwd. What does pwd print?
  1. Nothing, because cd .. undoes the previous command
  2. /Users/you/projects
  3. /Users/you/projects/campaign-report/data
  4. /Users/you/projects/campaign-report
Show the answer

/Users/you/projects/campaign-report

cd data goes down one level and cd .. comes back up one level, so you end where you started. cd .. doesn't undo anything; it always moves to the parent of wherever you are.

Making and changing files

CommandWhat it does
mkdir outputmakes a new folder called output (mkdir -p a/b/c makes nested folders in one go)
touch notes.txtcreates an empty file (or updates the date on an existing one)
cat notes.txtprints a file's contents
echo "Q3 review" > notes.txtwrites text into a file, replacing what was there
echo "Check CPC" >> notes.txtadds a line to the end of a file
cp notes.txt backup.txtcopies a file
mv notes.txt archive/moves a file; mv old.txt new.txt renames it
rm notes.txtdeletes a file (rm -r folder deletes a folder and everything in it)

echo prints whatever you give it. On its own it prints to the screen. The > sign redirects that output into a file instead. One > replaces the file's contents, and two >> add to the end of it. Mixing them up is a classic way to wipe a file, so give it a moment's thought every time.

Watch out: rm doesn't use the Trash. A deleted file is gone, with no "are you sure?" and no undo. rm -r on the wrong folder can remove a whole project. Run pwd and ls first so you know exactly what you're deleting.

Quick check
notes.txt contains three lines. You run echo "Final numbers" > notes.txt. What's in the file now?
  1. The three original lines, then Final numbers
  2. Only the line Final numbers
  3. Final numbers, then the three original lines
  4. Nothing changes, because echo only prints to the screen
Show the answer

Only the line Final numbers

A single > replaces the whole file with the new output. To keep the old lines and add one at the end, use >>.

Running programs

Every command you've typed so far is actually a small program. Python is a program too. To run a Python file, give its name to python3:

python3 report.py

On a Mac the command is python3, not python. Older guides say python, which on many Macs either doesn't exist or points at something else. (On Windows it's usually python or py.) Two quick checks:

python3 --version
which python3

The first prints the version. The academy's browser Python is 3.14, and your computer may have an older one. which shows the full path of the program a command will run. That helps when something "isn't found" or the wrong version runs.

A few habits that save time:

  • Up arrow brings back your previous command, so you can rerun or edit it.
  • history lists the commands you've typed recently.
  • Ctrl+C stops a program that's running too long or stuck in a loop.
  • clear wipes the screen when it gets cluttered (your files are untouched).

Reading a README's instructions

Open-source AI projects explain setup as a list of commands. Now you can read one:

cd ~/projects
git clone https://github.com/example/ad-analyzer.git
cd ad-analyzer
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python3 analyze.py

You already know cd and python3. git clone downloads a project (next lesson). The venv, source and pip lines set up the project's own Python packages (the lesson after that).

Sometimes two commands are joined with &&, as in cd ad-analyzer && python3 analyze.py. That means "run the second only if the first worked".

Quick check
In cd ad-analyzer && python3 analyze.py, what happens if the cd fails?
  1. The terminal closes
  2. The script runs in the current folder
  3. The Python script doesn't run
  4. The folder gets created
Show the answer

The Python script doesn't run

&& means "run the second only if the first worked", which stops you running a script from the wrong place.

Watch out: Don't paste commands you don't understand into your terminal. Be most careful with ones that start with sudo (run as administrator), or that send a download straight into the shell, like curl ... | sh. Those can change anything on your computer. If an AI assistant or a website suggests one, ask what each part does first.

Worked example: set up a report folder

Here's a short session from start to finish. Lines starting with % are what you type, and the other lines are what the terminal prints back:

% cd ~/projects
% mkdir -p q4-report/data
% cd q4-report
% echo "Q4 report notes" > notes.txt
% echo "Check search CPC" >> notes.txt
% cat notes.txt
Q4 report notes
Check search CPC
% ls
data  notes.txt
% pwd
/Users/sam/projects/q4-report

Step by step:

  1. mkdir -p makes q4-report and the data folder inside it in one go.
  2. cd moves into the new project folder.
  3. The first echo uses >, so it creates notes.txt with one line. The second uses >>, so it adds a line instead of replacing the first.
  4. cat shows both lines, ls shows the folder and the file, and pwd confirms where you are.

If the second echo had used a single >, cat would show only "Check search CPC".

Quick check
At the end of that session, you run rm notes.txt by mistake. Can you get the file back from the Trash?
  1. No: rm doesn't use the Trash, so the file is gone
  2. Yes: rm moves files to the Trash, and you can drag them back
  3. Yes, but only until you close the terminal window
  4. Yes: running cat notes.txt brings it back
Show the answer

No: rm doesn't use the Trash, so the file is gone

rm deletes for good, with no "are you sure?" and no undo. Run pwd and ls first, so you know exactly what you're deleting.

Practice what you just read

  • a practice exercise that checks your code
  • a 6-question quiz
  • 5 review cards for spaced repetition

Start this lesson

Try a quiz question

You're in /Users/sam/projects/site. You run cd ../blog. Where are you now?

  1. /Users/sam/projects/blog
  2. /Users/sam/projects/site/blog
  3. /Users/sam/blog
  4. /blog

Answer it at the end of the lesson to see if you're right, and why.

Before this lesson