The terminal, for reading an agent’s work
· #terminal #shell #tools
A coding agent does most of its work in a shell. It lists directories, reads files, searches them, builds the project, starts a server, sends a request and reads the reply. Each step is one line, and the lines go by quickly. A reader who knows perhaps thirty commands can follow all of it.
This post describes those commands. It is not a complete reference. The aim is to show the small part of the shell that appears again and again, and to explain it well enough that a new line is readable on first sight.
The commands behave as shown on macOS with zsh. Almost everything works the same in bash and on Linux; the few differences are noted.
Conventions
A line that begins with $ is a command typed at the prompt. The $ itself is not typed. Lines that follow without a $ are the output.
$ echo hello, world
hello, world
All examples use an imaginary user, Alice, and an imaginary website project in /Users/alice/projects/my-site. Names, addresses, numbers and output are invented for illustration. Domains and IP addresses come from the ranges reserved for documentation, such as example.com and 192.0.2.0/24.
1. The shape of a command
Every command has the same form: a name, then options, then arguments, separated by spaces.
$ ls -l src
Here ls is the name of the program, -l is an option, and src is an argument. Options change how the program behaves; arguments say what it works on. Single-letter options can be combined, so ls -l -a and ls -la are the same. Long options are spelled out with two dashes: --help, --port 8787.
The shell finds the program by searching the directories listed in the PATH variable. To see which file will run:
$ command -v node
/usr/local/bin/node
The manual page for most commands is shown by man, for example man ls. Press q to leave it. Many programs also accept --help.
2. Where you are
The shell always has a current directory. Commands that take a file name look for it there, unless the name says otherwise.
$ pwd
/Users/alice/projects/my-site
$ cd src/pages
$ pwd
/Users/alice/projects/my-site/src/pages
A path that begins with / is absolute: it starts at the root of the file system. Any other path is relative to the current directory. Four abbreviations appear everywhere:
| Path | Meaning |
|---|---|
. |
the current directory |
.. |
the parent directory |
~ |
your home directory |
- |
(with cd only) the previous directory |
So cd .. moves up one level, and cd ~ returns home. An agent often writes cd /full/path && command so that the command runs in the right place no matter where the shell was before.
3. Looking at files
ls lists a directory. With -l it prints one file per line with details; with -a it also shows names that begin with a dot, which are otherwise hidden.
$ ls -la src/assets/photos
total 512
drwxr-xr-x@ 5 alice staff 160 Mar 3 10:15 .
drwxr-xr-x@ 4 alice staff 128 Mar 3 10:12 ..
-rw-r--r--@ 1 alice staff 81920 Mar 3 10:15 beach.png
-rw-r--r--@ 1 alice staff 92160 Mar 3 10:15 forest.png
-rw-r--r--@ 1 alice staff 76800 Mar 3 10:15 mountain.png
The columns are: type and permissions, number of links, owner, group, size in bytes, time of last change, and name. The first character is d for a directory and - for a plain file. The next nine are read, write and execute permission (rwx) for the owner, the group and everyone else, in that order. On macOS a trailing @ means the file has extended attributes, such as a note of where it was downloaded from. total is the space used, in blocks of 512 bytes.
cat prints a whole file. For anything long, print only part of it:
$ head -n 5 package.json # first 5 lines
$ tail -n 20 build.log # last 20 lines
$ tail -f server.log # last lines, then keep printing new ones
$ sed -n '60,90p' src/styles.css # lines 60 to 90
$ wc -l src/utils.ts # count lines
42 src/utils.ts
The text after # is a comment; the shell ignores it.
The sed -n '60,90p' form is common in agent transcripts. It prints only lines 60 to 90, which is the cheapest way to read one part of a large file. Section 6 explains how it works.
4. Searching
grep prints the lines that match a pattern.
$ grep -n "button" src/styles.css
12:.button {
27:.button:hover {
31:.button-primary {
The options you will see most:
| Option | Effect |
|---|---|
-n |
show line numbers |
-i |
ignore case |
-r |
search every file under a directory |
-l |
print only the names of matching files |
-o |
print only the matching part of the line |
-E |
use extended patterns, where error|warn means either word |
-v |
print the lines that do not match |
So grep -rn "API_KEY" src finds every use of a name in a directory, and grep -E "error|warn" keeps only lines that mention either word.
find searches by name instead of content:
$ find src -name '*.md'
src/content/posts/second-post.md
src/content/posts/first-post.md
src/content/about.md
The names come out in the order they are stored on disk, not sorted. Pipe them through sort if the order matters.
Quote the pattern. Before the shell runs a command, it rewrites it. One of these rewrites is filename expansion. A word that contains * is treated as a pattern, and the shell replaces it with the names of the matching files in the current directory. The program receives those names; it never sees the *. echo shows this:
$ ls
README.md notes.md src
$ echo *.md
README.md notes.md
find needs the pattern itself, because it does its own matching in every directory it visits. Without quotes, the shell gets to the * first, and the result depends on which files happen to be in the directory you are in:
| Files here | You type | find receives |
Result |
|---|---|---|---|
no .md files |
find src -name *.md |
zsh stops with no matches found: *.md; bash passes *.md unchanged |
zsh: error. bash: works, by luck |
README.md |
find src -name *.md |
find src -name README.md |
wrong: finds only files named README.md |
README.md, notes.md |
find src -name *.md |
find src -name README.md notes.md |
error: notes.md is not valid there |
| anything | find src -name '*.md' |
find src -name *.md |
right: every .md file under src |
The quotes tell the shell to leave the text alone, so *.md reaches find unchanged. The second row is the dangerous one: there is no error, only fewer results than expected. The same rule applies to every program that does its own pattern matching, such as grep and sed.
5. Changing files
$ mkdir -p src/assets/photos # make a directory, and its parents if needed
$ cp ~/Downloads/beach.png src/assets/photos/ # copy
$ mv draft.md first-post.md # move or rename
$ rm old-notes.md # remove
$ chmod 644 beach.png # set permissions to rw-r--r--
rm does not use the Trash. A removed file is gone. rm -r removes a directory and everything in it, and rm -rf does so without asking. Read such a line twice.
The number given to chmod is three octal digits, one each for owner, group and others. Each digit is the sum of 4 (read), 2 (write) and 1 (execute), so 644 means read-write for the owner and read-only for everyone else, and 755 adds execute permission for all.
6. Editing text with sed
sed, the stream editor, changes text without opening it in an editor. It reads its input one line at a time, applies a short program called the script to each line, and prints the result. The general form is
$ sed [options] 'script' file
The script is quoted so that the shell passes it to sed unchanged. The file is not modified unless you ask for it with -i, described below. Without a file name, sed reads its standard input, so it also works at the end of a pipe.
Two kinds of script cover nearly every use in an agent transcript: printing selected lines, and replacing text. The examples below use this file:
$ cat src/content/posts/first-post.md
---
title: 'First post'
date: 2026-03-01
draft: false
---
Hello, world.
Printing selected lines
Normally sed prints every line it reads. The option -n turns that off, so that only the lines selected by the p (print) command appear. The script is an address, which says which lines, followed by the command p.
| Script | Prints |
|---|---|
sed -n '3p' |
line 3 |
sed -n '2,4p' |
lines 2 to 4 |
sed -n '4,$p' |
line 4 to the end; $ here means the last line |
sed -n '/draft/p' |
every line that contains draft, like grep draft |
$ sed -n '2,4p' src/content/posts/first-post.md
title: 'First post'
date: 2026-03-01
draft: false
Agents use this form to read one part of a long file, for example sed -n '60,90p' src/styles.css, without printing all of it. If -n is left out, every line is printed, and the selected ones appear twice.
Replacing text
The s (substitute) command has the form
s/pattern/replacement/flags
It finds pattern in each line and puts replacement in its place. Without flags, only the first match on each line is replaced. The flag g (global) replaces every match.
$ echo 'colour and colour' | sed 's/colour/color/'
color and colour
$ echo 'colour and colour' | sed 's/colour/color/g'
color and color
The pattern is a regular expression. Most characters match themselves, but a few have special meanings:
| In a pattern | Matches |
|---|---|
. |
any single character |
* |
zero or more of the character before it |
.* |
anything, including nothing |
^ |
the start of the line |
$ |
the end of the line |
\. |
a real dot; the backslash removes the special meaning |
So ^date: .* means: a line that starts with date: , followed by anything. Replacing it changes the whole line, whatever date was there before:
$ sed 's/^date: .*/date: 2026-03-04/' src/content/posts/first-post.md
---
title: 'First post'
date: 2026-03-04
draft: false
---
Hello, world.
The changed text is printed, but the file on disk is still the same. That makes this form a safe preview.
When the pattern itself contains /, as file paths do, choose a different separator. Any character that follows s becomes the separator:
$ sed 's#/old/path#/new/path#' config.txt
Several scripts can be given at once, each after -e. They are applied in order to every line:
$ sed -e 's/colour/color/g' -e 's/favour/favor/g' notes.md
Changing the file: -i
The option -i (in place) writes the result back into the file instead of printing it. This is where macOS and Linux differ. They ship different versions of sed, BSD and GNU, which read -i differently:
| System | Command | Backup copy |
|---|---|---|
macOS (BSD sed) |
sed -i '' 's/a/b/' file |
none; '' is an empty suffix |
Linux (GNU sed) |
sed -i 's/a/b/' file |
none |
| both | sed -i.bak 's/a/b/' file |
the original is kept as file.bak |
On macOS, -i always takes the word after it as the suffix for a backup copy, and '' means “no backup”. A command written for Linux therefore fails on a Mac: sed -i 's/a/b/' file takes s/a/b/ as the suffix and file as the script, and stops with an error such as invalid command code f. The opposite mistake fails on Linux, where '' is read as the script and s/a/b/ as a file name. The form -i.bak, with no space, works on both.
sed -i changes the file silently and keeps no copy unless asked. A careful sequence is:
- Run the command without
-iand read the output. - Run it again with
-i. - Check the change with
git diff, which shows exactly which lines changed (section 12.4).
When an agent edits a file with sed -i, the change appears in git diff in the same way, and git can undo it.
7. Input, output and errors
A program has one input and two outputs. Standard output carries its results. Standard error carries its complaints. Both go to the terminal unless they are redirected.
$ npm run build > build.log # stdout to a file, replacing it
$ npm run build >> build.log # stdout appended to the file
$ npm run build 2> errors.log # stderr to a file
$ npm run build > build.log 2>&1 # both to the same file
$ npm run build > /dev/null # discard stdout
The 2>&1 reads as “send stream 2 (stderr) wherever stream 1 (stdout) is going now”. Order matters: it must come after the > it refers to.
Every program also ends with an exit status, a small number. Zero means success; anything else means failure. The shell keeps the last status in $?.
$ grep -q "draft: true" src/content/posts/first-post.md
$ echo $?
1
Here grep -q prints nothing and only sets the status: 0 if it found a match, 1 if not. The post is not a draft, so the answer is 1. Exit status is what the operators in the next section test.
8. Combining commands
The pipe | connects the standard output of one command to the standard input of the next. This is the most useful idea in the shell. Small programs that each do one thing are joined into a larger one.
$ npm run build 2>&1 | grep -E "error|Complete!"
10:20:31 [build] Complete!
The build prints dozens of lines. The pipe sends all of them, errors included, to grep, which keeps only the two kinds that matter. An agent writes lines like this to keep its own context short. If you see it, read it from left to right: produce, then filter.
Commands can also be written one after another on a line:
| Separator | Meaning |
|---|---|
a ; b |
run a, then run b |
a && b |
run b only if a succeeded |
a || b |
run b only if a failed |
&& is the usual choice, because a chain stops at the first failure:
$ npm run build && npx wrangler deploy
If the build fails, nothing is deployed.
A line can be continued with a backslash at the very end. This is only for readability; the shell joins the lines before running them.
9. Variables and quoting
A variable is set with name=value, with no spaces around =, and read with $name.
$ D=src/assets/photos
$ mkdir -p $D && cp beach.png $D/ && cp forest.png $D/
Agents use variables to avoid repeating a long path. A variable set this way exists only in the current shell. To set one for a single command, put the assignment in front of it:
$ NODE_ENV=production npm run build
$(command) runs a command and puts its output in place:
$ echo "Built at $(date +%H:%M)"
Built at 10:21
Quotes control what the shell does to the text inside them.
- In single quotes nothing is special.
'$HOME'is five ordinary characters. - In double quotes
$and$(...)are still expanded, but spaces and*are not."$HOME"becomes your home directory.
When in doubt, quote. One difference between shells matters here: bash splits an unquoted variable into words at spaces, while zsh does not. A variable that holds several options, such as OPTS='--resolve example.com:443:192.0.2.10 -s', works when written as $OPTS in bash but is passed as one argument in zsh, which then fails. Write the options out directly instead.
10. Processes
A program that is running is a process. Most commands finish and return the prompt. A server does not; it runs until stopped.
| Action | How |
|---|---|
| stop the program in the foreground | Ctrl-C |
| start a program in the background | command & |
| list your background jobs | jobs |
| list processes | ps aux | grep node |
| stop a process by number | kill 4242 |
| force it to stop | kill -9 4242 |
The most common problem with servers is a port that is already taken. Here a development server holds port 4321:
$ lsof -i :4321
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 4242 alice 14u IPv6 0x1a2b3c4d 0t0 TCP localhost:rwhois (LISTEN)
lsof -i :4321 shows which process is listening on port 4321: a node process with number (PID) 4242. The port appears as rwhois because /etc/services gives 4321 that old name; add -P to see plain numbers. Stop the process with kill 4242, or start the new server on another port.
11. Talking to the network
curl sends an HTTP request and prints the response. It is the quickest way to check a site or an API without a browser.
$ curl -sI https://www.example.com/
HTTP/2 301
date: Tue, 03 Mar 2026 10:22:05 GMT
content-type: text/html; charset=UTF-8
location: https://example.com/
-s hides the progress bar, and -I asks for the headers only. Here the www address only sends visitors on, and the location header says where. The first line gives the status: 200 is success, 301 a permanent redirect, 404 not found, 5xx a server error. To send data:
$ curl -s -X POST http://localhost:8787/api/messages \
-H 'Content-Type: application/json' \
-d '{"name":"Test","message":"Hello"}'
-X sets the method, -H adds a header and -d supplies the body. Add -i to see the response headers as well as the body.
dig asks the domain name system where a name points:
$ dig +short example.com
192.0.2.10
198.51.100.7
$ dig +short example.com @1.1.1.1
198.51.100.7
192.0.2.10
This name has two addresses. The order varies between answers and does not matter. The second form asks a public resolver, here 1.1.1.1, directly. If the two answers differ, a cache somewhere between you and the internet, often the home router, is still holding an old answer. It expires by itself.
12. Project tools
The commands so far belong to the shell and come with every Unix system. The rest of a typical transcript belongs to the tools of the project itself. In a JavaScript web project hosted on Cloudflare these are npm, npx, wrangler and git. Each is described below in the same order: what it is, which files it reads, and the commands that appear most.
12.1 npm
What it is. Node.js runs JavaScript outside a browser. npm, the Node Package Manager, is installed with it. It downloads libraries, called packages, from a public registry at npmjs.com, and it runs the project’s own tasks.
The files it uses.
| File | Purpose |
|---|---|
package.json |
The project’s manifest: its name, the packages it needs and named tasks called scripts. Written by people. |
package-lock.json |
The exact version of every package installed, including the packages those packages need. Written by npm; commit it, never edit it. |
node_modules/ |
The installed packages themselves. Created by npm install; never commit it, since it can always be rebuilt. |
A small package.json looks like this:
{
"name": "my-site",
"scripts": {
"dev": "astro dev",
"build": "astro build",
"deploy": "astro build && wrangler deploy"
},
"dependencies": { "astro": "^5.0.0" },
"devDependencies": { "wrangler": "^4.0.0" }
}
dependencies are needed by the finished site; devDependencies only while developing and building it. The ^ in ^5.0.0 allows any later 5.x version. The lock file then records which one was actually chosen.
The commands.
$ npm install # install everything package.json lists
$ npm ci # clean install: exactly what package-lock.json says
$ npm install astro # add a package to dependencies
$ npm install -D wrangler # add a package to devDependencies
$ npm run build # run the script named "build"
$ npm outdated # list packages that have newer versions
npm run build looks up "build" in the scripts section and runs the command written there, astro build. So when an agent runs npm run build, open package.json to see what really happens. npm ci is what build servers use: it deletes node_modules and installs exactly the locked versions, so every build starts from the same state.
12.2 npx
What it is. Many packages contain a program as well as a library: astro, wrangler and prettier are examples. When installed, these programs are put in node_modules/.bin. That directory is not in PATH, so typing wrangler alone usually fails with command not found.
npx runs such a program by name:
$ npx wrangler --version
4.12.0
It looks for the program in the project’s node_modules/.bin first. If it is not there, npx offers to download the package into a temporary cache and run it from there. That is how one-off tools are started without installing them, for example npx create-astro@latest to start a new project.
Two points explain most of what you will see:
- Scripts in
package.jsondo not neednpx. Whilenpm runis running a script, it addsnode_modules/.bintoPATH, so a script can simply saywrangler deploy. npx wrangler deployandnpm run deploymay do different things. The first runs one program. The second runs whatever thedeployscript says, which may include a build first.
12.3 wrangler
What it is. Cloudflare Workers is a service that runs your code on Cloudflare’s servers in many cities, close to each visitor. A Worker can serve a static site, answer API requests, or both. wrangler is Cloudflare’s command-line tool for developing, configuring and publishing Workers. It is installed per project with npm install -D wrangler and run with npx wrangler.
The files it uses.
| File | Purpose |
|---|---|
wrangler.jsonc or wrangler.toml |
The Worker’s configuration: its name, the entry file, the domains it answers on, and the resources it is connected to (databases, storage, email). |
.dev.vars |
Secret values for local development only. Never commit it. |
.wrangler/ |
Local state: the local copy of databases, caches and logs. Safe to delete; never commit it. |
The connections to resources are called bindings. A binding gives a resource a name inside the code. For example, a D1 database (Cloudflare’s SQLite database service) bound as DB is used in the code as env.DB.
Local and remote. Most wrangler commands can act either on your own machine or on Cloudflare. This difference matters more than any other when reading a transcript.
| Command | Acts on |
|---|---|
wrangler dev |
your machine: runs the Worker locally, with local copies of its databases |
wrangler d1 execute my-db --local ... |
the local copy of the database |
wrangler d1 execute my-db --remote ... |
the real database on Cloudflare |
wrangler deploy |
Cloudflare: publishes the Worker to the internet |
wrangler secret put NAME |
Cloudflare: stores an encrypted value for the deployed Worker |
The commands.
$ npx wrangler login # sign in; opens a browser once
$ npx wrangler whoami # show which account is signed in
$ npx wrangler dev # run the Worker locally
$ npx wrangler deploy # publish it
$ npx wrangler tail # stream live logs from the deployed Worker
$ npx wrangler secret put API_KEY # store a secret; it prompts for the value
$ npx wrangler d1 create my-db # create a database
$ npx wrangler d1 migrations apply my-db --remote
$ npx wrangler d1 execute my-db --remote \
--command "SELECT id, name FROM messages ORDER BY id DESC LIMIT 5"
A migration is a numbered SQL file that changes the shape of the database, for example by creating a table. migrations apply runs, in order, the files that have not run yet on that database, and remembers which ones have. Running it with --local first and --remote afterwards is the usual pattern: test the change locally, then apply it to the real database.
12.4 git
What it is. git records the history of a project as a series of commits, each a snapshot of the files with a message. GitHub stores a copy of that history online, and many hosting services publish a site whenever new commits arrive there.
A change passes through three places:
| Place | How it gets there |
|---|---|
| working directory | you, or an agent, edit a file |
| staging area | git add marks the change for the next commit |
| history | git commit records the staged changes; git push sends them to GitHub |
$ git status # what has changed, and what is staged
$ git diff # the changes themselves
$ git add -A # stage every change
$ git commit -m "message" # record the staged changes
$ git push # send commits to GitHub
$ git log --oneline -3 # the last three commits
a1b2c3d Add second post
9f8e7d6 Fix header on small screens
4c5d6e7 Add first post
Each commit is shown by the first seven characters of its hash, a unique identifier, then its message.
12.5 Lines to read twice
Most commands only read, or change files that git can restore. A few act outside your machine or cannot be undone:
wrangler deploy: changes the live site.wrangler d1 ... --remoteandwrangler secret put: change real data or settings on Cloudflare.git push: publishes commits, and may start an automatic deploy.rm, especiallyrm -rf: deletes files permanently.
These are the lines to read before they run.
13. Reading a long line
Here is a typical agent line, taken apart.
$ cd /Users/alice/projects/my-site && npm run build 2>&1 | grep -E "error|Complete!"; ls dist/_astro | grep -i webp
10:20:31 [build] Complete!
beach.Xk3f9QaB.webp
forest.Lm7pR2sD.webp
mountain.Tq4wZ8nE.webp
cd /Users/alice/projects/my-sitemoves to the project.&&continues only if that worked.npm run build 2>&1builds the site, with errors merged into normal output.| grep -E "error|Complete!"keeps only error lines and the final success line.;then runs the next command whatever happened.ls dist/_astro | grep -i webplists the built files and keeps the WebP images, converted from PNG during the build. The random-looking part of each name changes when the image changes, so browsers never show a stale copy.
Any long line can be read the same way: split it at &&, ||, ; and |, and read each piece on its own.
Summary
| Purpose | Commands |
|---|---|
| Where am I | pwd, cd, ls -la |
| Read files | cat, head, tail, wc -l |
| Search | grep -rn, find -name |
| Change files | mkdir -p, cp, mv, rm, chmod |
| Edit text | sed -n 'a,bp', sed 's/old/new/g', sed -i |
| Redirect output | >, >>, 2>&1, /dev/null |
| Combine | |, &&, ||, ; |
| Variables | name=value, $name, $(command), quotes |
| Processes | Ctrl-C, &, ps, kill, lsof -i |
| Network | curl -sI, curl -X POST, dig +short |
| Project | npm, npx, wrangler, git |
Further reading
Each tool documents itself. On any Unix system man followed by a command name shows its manual, and that is the first place to look. For more depth:
The shell
- The Missing Semester of Your CS Education: MIT’s short course on the shell, editors and tools.
- The Linux Command Line by William Shotts: a complete introduction, free to read online.
- Bash Reference Manual and Zsh Manual: redirection, quoting, variables and expansion in full.
Text tools
- grep manual page
- sed manual page and Grymoire’s sed tutorial, a long, example-driven introduction
- curl documentation
Project tools
- npm CLI documentation: every command, plus package.json and npx.
- Wrangler documentation: installation, commands and configuration.
- Cloudflare Workers documentation and D1 documentation
- Pro Git by Scott Chacon and Ben Straub: the standard book on git, free online.