The terminal, and why it is not optional

The handful of commands that cover ninety per cent of a backend engineer's day, and why the GUI cannot replace them.

9 min read🧭 Programming Foundations

The terminal is a text conversation with your machine. You type an instruction, it answers. That is all it is, and the reason it will not go away is that text is the only interface that can be written down — scripted, logged, put in a pipeline, pasted into a ticket by somebody trying to help you.

A backend engineer lives here. Not because the GUI is bad, but because the servers your code runs on have no GUI at all.

The shape of a command

plaintext
javac -d out Hello.java
─────  ── ─── ──────────
  │     │   │      │
  │     │   │      └── argument: what to act on
  │     │   └───────── the flag's value
  │     └───────────── flag: changes how it behaves
  └─────────────────── the program to run

Everything follows that shape. Once you see it, an unfamiliar command stops being noise: you can tell which part is the program and which parts are instructions to it, even when you know nothing about the tool.

Two conventions worth knowing immediately: a single dash usually introduces a one-letter flag (-d), two dashes a word (--release), and almost every program answers --help.

The commands that cover most days

CommandWhat it doesThe one thing to remember
pwdprint working directory"where am I" — the answer to most confusion
lslist filesls -la shows hidden files and details
cdchange directorycd .. goes up; cd alone goes home
catprint a filefine for small files, terrible for large ones
lesspage through a fileq quits. Everybody forgets this once
grepfind lines matching a patterngrep -r "text" . searches a whole tree
tailthe end of a filetail -f app.log follows it live — the one you will use most
mkdirmake a directory-p makes parents too
cp / mv / rmcopy, move, removerm does not ask, and there is no bin

That last row deserves its own warning.

Piping: the idea that makes it powerful

Any program's output can become the next program's input, with |:

bash
grep ERROR app.log | tail -20

Find the lines with ERROR, then show me the last twenty of those. Neither program knows about the other. grep does one thing, tail does one thing, and the pipe composes them.

This is the whole philosophy, and it is why the tools are so small: you are not meant to find one program that does what you want. You are meant to join three.

bash
grep ERROR app.log | grep -v Timeout | wc -l

Count the error lines that are not timeouts. Three tools, one question answered, and you could keep going.

Watch it narrow

The argument for pipes is easier to believe with numbers on it. A log file with two hundred lines in it:

plaintext
$ wc -l app.log
200
 
$ grep ERROR app.log | wc -l
90
 
$ grep ERROR app.log | grep -v Timeout | wc -l
35

200 → 90 → 35. Each stage hands its output to the next as plain text, and nothing in the middle is written to disk or held anywhere you could look at. Then swap the counter for the thing you actually wanted:

plaintext
$ grep ERROR app.log | grep -v Timeout | tail -3
2026-09-12T10:15:00Z ERROR NullPointerException in OrderMapper
2026-09-12T10:17:00Z ERROR NullPointerException in OrderMapper
2026-09-12T10:18:00Z ERROR NullPointerException in OrderMapper

Two hundred lines to the three that matter, with no program written and nothing installed. Notice what happened at the second stage in particular: grep -v Timeout threw away fifty-five error lines as noise you already know about, which is the move that turns an unreadable log into a readable one.

Where you will actually use it

Not for writing code — you have an IDE for that. For everything around it:

  • Reading a log on a server that has nothing else
  • tail -f while you reproduce a bug
  • Running the build, the tests, the container
  • Git
  • Finding which of 4,000 files mentions a class name
  • Being inside a container, where there is nothing but a shell

Under the hood: what a pipe actually is, and what "the shell" is doing

grep ERROR app.log | tail -20 looks like one operation. It is the shell doing three distinct things, and knowing them explains why pipelines behave the way they do.

Every process starts with three open file descriptors — small integers the OS uses as handles to something it can read from or write to. 0 is stdin, 1 is stdout, 2 is stderr. A program that calls System.out.println is writing to file descriptor 1; it has no idea, and does not need to know, whether that descriptor is connected to your terminal, a file, or another program.

The shell creates the processes and wires the descriptors before either program runs a line of code. For a | b, the shell asks the OS for a pipe — a kernel-managed buffer with a read end and a write end — then starts a with its stdout (fd 1) pointed at the pipe's write end, and starts b with its stdin (fd 0) pointed at the pipe's read end. Neither program's code changed; the shell just handed each of them a different descriptor before main ran. That is also why 2>&1 (redirect stderr to wherever stdout is currently going) and > file (redirect stdout to a file instead of the terminal) use the same mechanism — they are all just "which descriptor does fd 1 point at."

An exit code is the other channel, separate from any of that. A process returns a small integer to its parent when it finishes — 0 conventionally means success, anything else means failure, and the specific non-zero value is the program's own choice of what to report. The shell exposes the most recent one as $?. A pipeline like a | b reports b's exit code by default — a can fail silently in the middle of a pipeline unless you know to check ${PIPESTATUS[0]} (bash) for it.

Try it yourself

Trace where each descriptor goes

Run this, and before you do, predict what appears on your screen versus what ends up in out.txt:

bash
{ echo "to stdout"; echo "to stderr" >&2; } > out.txt
cat out.txt
Which descriptor each line used

echo "to stdout" writes to fd 1, which the > out.txt redirected to the file — so it never reaches your screen, and cat out.txt shows it. echo "to stderr" >&2 explicitly writes to fd 2, which the redirect never touched, so it still goes to the terminal and appears immediately, before you even run cat. Two echo commands, inside the same braces, writing to two different descriptors that happen to both start out pointed at your terminal — and one line of redirection changed where only one of them goes. This is the same reason 2>&1 has to come after a > redirect to work as "send stderr to the same place stdout now goes" — order matters because each redirect only changes where a descriptor points at that moment.

Ten minutes that pay for themselves

In a terminal, without looking anything up beyond --help:

  1. Find out where you are, then list everything including hidden files.
  2. Make a directory, move into it, create a file with some text in it, and print it.
  3. Search your whole home directory for files whose name contains "java" — and notice how long it takes and how much it prints.
  4. Run ls --help (or man ls) and find the flag that sorts by modification time.
The commands
bash
pwd
ls -la
 
mkdir scratch && cd scratch
echo "hello" > note.txt
cat note.txt
 
find ~ -iname "*java*"
 
ls --help | grep -i "sort"    # -t sorts by time

Step 3 is the instructive one: it prints more than you expected, and it is slow. That is what teaches you to narrow a search before running it — a habit that matters far more on a server with a million files than on your laptop.

Misconceptions

  • "The terminal is for experts." It is for anybody who wants to repeat what they did. A click cannot be pasted into a runbook.
  • "I'll learn it when I need it." You need it the first time production is broken, which is the worst moment to be learning tail.
  • "Memorising commands is the skill." The skill is knowing a tool exists and that --help will tell you the rest. Nobody remembers tar's flags.

Sources

  • The Open Group Base Specifications (POSIX.1-2017), dup2, pipe — the file-descriptor and pipe mechanisms every shell builds on.
  • bash(1) and zsh(1) man pages — redirection (2>&1), $?, PIPESTATUS, and set -e's subshell behaviour.
  • Kernighan & Pike, The Unix Programming Environment — the original statement of "small tools, composed with pipes."
Progress is saved on this device and to your account when signed in.