AI Learning Hub › Learn AI › Self-Paced Courses › Terminal on Mac: Reading Commands Before You Run Them › Reading a Command an Agent Wrote

Module 9 ยท Beginner

Reading a Command an Agent Wrote

Six questions to ask of any command you did not write, and what to do with a multi-line block that arrives ready to paste.

By the end

  • Work through six questions on any command you did not write
  • Spot the parts of a command that widen what it touches
  • Handle a multi-line block that arrives ready to paste
  • Decide to run, narrow, or decline

This is what the course has been building toward. An AI coding agent will propose terminal commands — sometimes asking permission first, sometimes presenting a block to copy. Those commands are usually fine. The problem is that “usually fine” is not something you can act on unless you can tell the difference.

You now can. Everything in the previous eight modules was the vocabulary; this is reading the sentence.

Six questions

Ask these of any command you did not write. They take about twenty seconds once they are habit, and they are ordered so the two that matter most come first.

  1. Command — what program is being asked to run?
  2. Location — which folder will it run in?
  3. Scope — which files do the paths and any * actually match?
  4. Action — does it read, create, copy, move, overwrite, or remove?
  5. Operators — is there a |, a >, a >>, or an &&?
  6. Privilege — does it start with sudo?

Location comes second for a reason. A relative path is meaningless until you know where you are standing, and most agent-proposed commands use relative paths. If you cannot answer question two, questions three and four have no answer either.

What widens a command

Four things make a command reach further than its text suggests, and all four have appeared earlier in the course.

A wildcard
One * turns a named file into however many files happen to match. echo in place of the real command shows you the list.
Recursion
-r or -R means the folder and everything beneath it, however deep.
A relative path
Means something different depending on the current folder. . means everything here.
Elevation
sudo removes the limits that would otherwise have contained a mistake.

Blocks that arrive ready to paste

An agent often hands over several commands at once. That shape is worth understanding before you meet it.

In the version of Terminal tested for this course, pasting a multi-line block did not run anything. The lines appeared on the command line, highlighted, waiting. Pressing Return then ran all of them in sequence. No dialog appeared and nothing asked for confirmation.

Read every line before you press Return. Pasting is the safe part; the single keystroke afterward is what commits to the whole block. Do not count on being warned — nothing warned during testing, and behavior can vary with settings and with which terminal you are using.

If a block is long or you are unsure of one line, paste it into a text editor first, or run the lines one at a time. Neither costs anything.

Worth knowing about history

Pressing the Up Arrow brings back the previous command, which is the most-used key in a terminal. It also means your commands persist: what you typed is recorded, and something you paste into a command line can be recalled later.

The practical consequence is small but real. Avoid putting passwords, API keys or tokens directly into a command when you can avoid it. Not because something sinister will happen, but because a command line is a surprisingly durable place to leave one.

Exercise: six commands, three verdicts

Below are six commands of the kind an agent produces. Do not run them. Assume you are in ~/terminal-practice.

Work through the six questions on each, then give it a verdict: safe to run, needs narrowing, or decline.

Read these — do not run them

1.  grep -R "Jackson" . | wc -l

2.  mkdir summaries && cp cases/*.txt summaries/

3.  rm *.txt

4.  find . -name "*.txt" > output/inventory.txt

5.  cd ~ && rm -r output

6.  sudo cp cases/opinion-a.txt /usr/local/share/
Check your verdicts

1 — safe. Reads only. A pipe moves output between two commands and nothing is written anywhere.

2 — safe. Creates a folder, then copies two files into it. The && means the copy is skipped if the folder could not be made. The wildcard matches exactly the two files in cases, which echo cases/*.txt would confirm.

3 — needs narrowing. Run from the practice folder root it matches nothing, because the .txt files are in subfolders. Run from notes it removes three. The command is dangerous precisely because its effect depends on where it runs, and nothing in the line tells you. If the task was “remove the draft”, name the draft.

4 — safe, with one thing to notice. It writes a file. The > replaces whatever was in output/inventory.txt. Here that file does not exist yet, so nothing is lost — but the same line run a second time silently discards the first result.

5 — decline, or at minimum narrow. The cd ~ moves to your home folder, so rm -r output no longer refers to the practice folder’s output. It refers to any folder called output in your home directory, which may be something else entirely. This is question two doing its work: the command looks local and is not.

6 — decline. Copying a fictional case file into a system folder serves no purpose the task could plausibly require, and it is elevated. Neither half is catastrophic; together they are a command whose justification you cannot reconstruct. “I cannot see why this is necessary” is a sufficient reason to decline.

Notice that only one of the six was genuinely objectionable, and two more deserved a change. That ratio is about right. The point of the six questions is not suspicion — it is being able to tell quickly which is which.

If you want more on what agents are and how they work, Agents Without the Hype covers the concepts, and VS Code: Files, Changes, and AI Agents covers reviewing the file changes an agent makes once the commands have run.