AI Learning Hub › Learn AI › Self-Paced Courses › Terminal on Mac: Reading Commands Before You Run Them › Inspect Before You Run

Capstone

Inspect Before You Run

A proposed set of commands arrives to tidy a research folder. Work out what each one would do, find the one that reaches further than the task asked for, narrow it, and run only what you meant to.

What this asks of you

  • Establish which folder you are in
  • Read five commands you did not write
  • Find the one that reaches further than the task asked for
  • Narrow it, run the rest, and check the result
  • Say what changed and what you prevented

Everything in this course has been building toward one task: look at a command somebody else wrote and work out what it will do before it does it.

Set aside about sixteen minutes. Do the reading before any of the running — the exercise does not work the other way round.

Start from a clean folder

Delete your terminal-practice folder and unzip the download again, so earlier exercises do not confuse the picture. Then:

Set up

cd ~/terminal-practice
pwd
ls

You need no AI account for this. The commands below are supplied.

The task

Imagine you asked an assistant to do one thing:

Collect the two opinions into a folder called summaries, and write a list of every text file into output/inventory.txt.

Here is what came back.

Proposed commands — read, do not run

cd ~/terminal-practice
mkdir summaries
cp cases/*.txt summaries/
find . -name "*.txt" > output/inventory.txt
rm */*.txt

Step 1 — Read each line

For every line, write down the six answers. Do this on paper before going near the terminal.

The six questions to answer for each proposed command
QuestionWhat you are looking for
CommandWhich program runs
LocationWhich folder it runs in
ScopeWhich files the paths and any * match
ActionRead, create, copy, move, overwrite, remove
Operators|, >, >>, &&
PrivilegeWhether it uses sudo

Step 2 — Check the scope you are unsure about

Two lines contain a wildcard. You can see exactly what each one matches without running the real command, by putting echo in front of the pattern.

Safe to run — these only print

echo cases/*.txt
echo */*.txt

Compare the two lists. One of them should stop you.

Then ask a second question the first one hides: these patterns are being read now, against the folder as it stands. Two of the proposed lines create files before the fifth one runs. Would the list you just printed still be the list?

Step 3 — Which line is wrong?

Four of the five commands do what the task asked. One does something the task never mentioned. Identify it, and say in one sentence what it would destroy.

Answer key — open after you have written your own

Lines 1 to 4 are fine.

cd ~/terminal-practice sets the location, using an absolute path, so the rest is predictable. mkdir summaries creates a folder. cp cases/*.txt summaries/ copies two files — echo confirms the pattern matches opinion-a.txt and opinion-b.txt and nothing else. find . -name "*.txt" > output/inventory.txt writes the list; the > would replace that file’s contents, but it does not exist yet, so nothing is lost. Note the quoting on the pattern — without it the command would have failed in the shell.

It writes eight paths rather than the five you started with, which is worth a second look. Two of them are the copies the previous line just made in summaries. The eighth is output/inventory.txt itself: the shell creates that file for the redirect before find starts walking, so find meets it on the way past. Nothing here is wrong, but if you predicted five, notice why — the folder had changed since you read the task.

Line 5 is the problem: rm */*.txt.

Nothing in the task asked for anything to be deleted. The pattern */*.txt means every .txt file one level down in any folder — which, by the time this line runs, is both opinions in cases, all three files in notes, the two fresh copies in summaries, and the inventory in output. Eight files across four folders: the originals, the copies, and the list of them all.

It is a short line and it does not look dramatic. That is the point: scope does not announce itself, and */* is wider than * in a way nothing in the text signals.

Step 4 — Narrow it, or drop it

Decide what the fifth line should have been. There is a defensible case for removing it entirely, since the task never asked for a removal, and a defensible case for a narrow version if you believe a cleanup was intended.

Write your replacement down before reading on.

Step 5 — Run what you decided

Run the first four lines. Type them rather than pasting, which gives you one more look at each.

Then run your replacement for line five, if you kept one.

Step 6 — Check the result

Verify

ls summaries
cat output/inventory.txt
ls cases
ls notes

Confirm that summaries holds two files, that the inventory lists eight paths, and that cases and notes still contain everything they started with.

Step 7 — Write it down

Two sentences. One saying what changed on disk. One saying what you prevented, and how you knew.

A reasonable answer

What changed: a summaries folder now holds copies of both opinions, and output/inventory.txt lists eight paths — the five originals, the two copies, and itself. Nothing was removed.

What was prevented: the last proposed line would have deleted eight files across four folders, including the two it had just copied, the three research notes that were never mentioned in the task, and the inventory the line before it produced. echo */*.txt printed five before anything ran, and reading the sequence in order showed where the other three would come from.

If your wording is different but your two lists match, you have it.

What you just did

You read five commands written by somebody else, established which folder they would run in, worked out which files each one would touch, found the one whose reach exceeded the request, checked your reasoning with a command that could not do any harm, and then ran only what you meant to run.

That is the whole skill, and it does not depend on remembering command names. It depends on reading — which is why you were allowed to use man and the earlier modules throughout.

Where to go next. VS Code: Files, Changes, and AI Agents covers reviewing the file changes an agent makes once its commands have run. GitHub Without the Jargon covers version control, which is the other way of making a mistake recoverable. Agents Without the Hype covers what agents are and how they pursue goals.