P.2 · The Terminal

P.2 · 45 min

The Terminal

Claude Code lives in the terminal. Every lab in this course starts with you typing a command into a dark window, and if that window makes your shoulders tense, the tension will quietly tax everything you build on top of it. The fix is not a 400-page book. It is about fifteen commands, two concepts, and an hour of your hands on the keys.

The map

A terminal is a text conversation with your computer. You type a command, the shell (the program running the conversation, usually zsh on macOS or bash on Linux) finds the matching program, runs it, and shows you what it printed. That is the whole model. Everything below is vocabulary for that conversation.

You are always "in" a directory, called the working directory. Commands operate relative to it unless you give a full path. The core moves:

  • pwd prints where you are
  • ls lists what is here (ls -la includes hidden files and details)
  • cd somewhere moves you (cd .. goes up one level, cd alone goes home)
  • mkdir -p a/b creates directories, including parents
  • cat file prints a file's contents
  • cp from to copies, mv from to moves or renames, rm file deletes
  • find . -name "*.txt" searches for files by name from here down
  • grep word file prints lines in a file containing a word

Two operators turn commands from single moves into sentences. The redirect > sends a command's output into a file instead of the screen, overwriting the file; >> appends instead. The pipe | feeds one command's output into the next command's input. grep hot leads.txt | wc -l means "find the lines containing hot, then count them." Small tools, composed. That composition style is the terminal's entire personality, and it is also how you will read half the commands Claude Code proposes to run.

Two concepts explain almost every beginner error:

Permissions. Every file carries flags for who may read, write, or execute it. A fresh script is not executable, so running ./report.sh fails with permission denied until you run chmod +x report.sh. When you see permission denied, your first thought should be "flags," not "I am in trouble."

Environment variables and PATH. The shell keeps named values, like REGION=us-east, that programs can read. Set one with export REGION="us-east", read it with echo $REGION. One of these variables, PATH, is a list of directories the shell searches when you type a command name. command not found almost always means the program is not installed or its directory is not on PATH. Those two errors, permission denied and command not found, account for most early terminal grief, and now you can diagnose both.

Tutor first

Before the gauntlet, calibrate. This prompt gives Claude the job of finding your actual level and drilling exactly there:

PromptTerminal tutor

You are my terminal tutor. I am learning to work in a Unix shell. Quiz me one question at a time, every question applied: "what command would you type to accomplish X" or "what will this pipeline print." Start easy (navigation, listing files) and escalate through pipes, redirection, permissions, and PATH. When I miss one, have me type the real command in my terminal and report back what happened before you continue. Stop after 10 questions and list what I should drill again tomorrow.

The gauntlet

Real reps, in your real terminal, with a check after every step. Type every command yourself. Copy-paste teaches your clipboard.

Lablab-p-2The terminal gauntlet

Goal: Run one continuous scenario that exercises navigation, files, pipes, redirection, variables, permissions, and cleanup, verifying each step.

Open your terminal. macOS: the Terminal app. Windows: install WSL first (search "install WSL", it is one command in PowerShell), then use its Ubuntu shell. Linux: you know where it is.

  1. Find out where you are, then go home and set up a workspace:
pwd
cd
mkdir -p practice/inbox practice/archive
cd practice

Check: pwd now ends in /practice. ls shows archive and inbox.

  1. Create a file with redirection, then append to it:
echo "Dana Whitfield - hot - demo booked" > inbox/leads.txt
echo "Marcus Lee - warm - opened email" >> inbox/leads.txt
echo "Priya Nair - hot - asked for pricing" >> inbox/leads.txt
cat inbox/leads.txt

Check: cat prints exactly three lines, in that order. If you see one line, you used > where you meant >> and overwrote your own work. Rebuild the file; that mistake is the lesson.

  1. Copy, then rename:
cp inbox/leads.txt archive/leads-backup.txt
mv inbox/leads.txt inbox/leads-monday.txt
ls inbox archive

Check: inbox contains only leads-monday.txt; archive contains leads-backup.txt. Note that rename and move are the same command.

  1. Search and compose. How many hot leads?
grep hot inbox/leads-monday.txt
grep hot inbox/leads-monday.txt | wc -l

Check: the first command prints the Dana and Priya lines. The second prints 2 (possibly padded with spaces; that is fine). Say the second command out loud as a sentence: find the hot lines, count them.

  1. Set an environment variable and read it back:
export REGION="us-east"
echo $REGION

Check: prints us-east. Now open a second terminal window and run echo $REGION there: empty. Environment variables live per shell session, which is exactly why deployment configs feel confusing later. You just learned the reason in ten seconds.

  1. Write a script, hit the permissions wall, fix it:
printf '#!/bin/bash\necho "Report for $REGION: $(grep -c hot inbox/leads-monday.txt) hot leads"\n' > report.sh
./report.sh

Check: permission denied. Good, you were supposed to hit that. Now:

chmod +x report.sh
./report.sh

Check: prints Report for us-east: 2 hot leads. One command, three of today's concepts working together: a variable, a permission fix, and a grep.

  1. Find files, then clean up deliberately:
find . -name "*.txt"
rm archive/leads-backup.txt
ls archive

Check: find listed both txt files with their paths; after rm, ls archive prints nothing. There is no trash can here. rm is forever, which is why you will learn git next lesson and stop fearing it.

Verify

  • ./report.sh runs and reports 2 hot leads.
  • You can explain, without looking, what grep hot file | wc -l does and why > destroyed your file in step 2 if it did.
  • echo $PATH prints a colon-separated list of directories, and you can say in one sentence what the shell uses that list for.
>Troubleshooting
  • command not found on something from this lab. You are probably not in a bash or zsh shell (Windows PowerShell will fail on most of these). Confirm with echo $0. On Windows, everything in this course happens inside WSL.
  • No such file or directory. You are not where you think you are. Run pwd and ls, reorient, continue. This reflex (pwd, ls, breathe) solves a third of all terminal problems.
  • The script prints 0 hot leads. Check that inbox/leads-monday.txt still exists and has three lines with cat, and that you are running the script from inside the practice directory, since its grep uses a relative path.

Where it breaks

The classic self-inflicted wounds, so you recognize them early. Overwriting a file with > when you meant >> you just did on purpose. Running rm with a wildcard you did not test first: before any rm with a * in it, run ls with the same pattern and look at what matched. And the big one culturally associated with terminals, sudo: it runs a command as the system administrator. You will need it rarely, and a beginner reflex of "add sudo until it works" turns small permission questions into system-level mistakes. If a command fails without sudo, ask your tutor why before escalating.

One more habit worth installing now: when Claude Code later proposes terminal commands, you will approve them before they run. Approving a command you cannot read is signing a contract you cannot read. This lesson is what makes those approvals informed consent instead of a reflex.

Knowledge check

Knowledge check

Q1You run ./deploy.sh and get 'permission denied'. What is the diagnosis and fix?
Q2What does grep ERROR server.log | wc -l print?
Q3A teammate says 'I installed the tool but the terminal says command not found.' Which question gets to the cause fastest?
Q4You are about to delete some old files with a wildcard in the rm command. What is the professional move first?

Sources

This lesson teaches shell fundamentals that have been stable for decades: no version-sensitive claims to cite. When you meet a command you do not recognize, man pages and your tutor prompt are the primary sources. Every gauntlet command and its expected output was executed and verified during authoring (July 2026).