0 / 91
Week 1 · Day 4 of 91

Command-line survival skills

Orientation, CLI, and the Web

Objective

Use commands as small, inspectable operations and read their output.

Treat the web as a connected system: the browser is a control panel, HTTP is the protocol, the server is the controller, and the database is persistent storage.

  • commands, flags, arguments
  • standard output and errors
  • command history and help

Why this matters

On Day 3 you learned where files live and how to move between folders. Today you learn to operate on them — copy, rename, inspect, delete — and, more importantly, to read what the terminal says back. Command output is the only evidence you get, and reading it is the difference between fixing a problem and guessing. By the end you can meet an unfamiliar command and work out what it does unaided.

Commands, flags, and arguments

Every line you type in a terminal has the same shape — three parts, always in this order:

ls -l notes
  • Commandls. The program you want to run.
  • Flag (also called an option or switch) — -l. A setting that changes how the command behaves. Flags start with a dash and are optional.
  • Argumentnotes. The thing the command acts on: which directory to list.

That is the whole grammar. ls alone lists the current directory in plain columns. ls -l lists the same files in long form — one per line with size, date, and permissions. Same command, same files, different behaviour. That is precisely what a flag is for.

Short flags are one dash and one letter — -l, -a — and usually stack, so ls -la equals ls -l -a. Long flags are two dashes and a word: --version, --help. You used one on Day 2 when you ran node --version.

Flags are DIP switches, arguments are the input signal

A bench instrument has a signal input and a bank of configuration switches. The switches supply no measurement — they decide how the instrument treats whatever arrives. Arguments are the signal; flags are the switches. Flip one and the same input yields a differently formatted reading.

Twenty seconds, right now

Run ls, then ls -l, then ls -la in any folder. Same command, same files, three amounts of detail. Nothing changed on disk — only how it was reported.

What the command says back

A command can write to two separate output channels. Both land on your screen, which hides that they are different.

  • Standard output (stdout) — the normal result, what the command produced when it worked.
  • Standard error (stderr) — complaints: errors, warnings, anything that went wrong.

They stay apart so you can send the result somewhere while still seeing problems. > redirects stdout into a file; 2> redirects stderr.

ls missing.txt > out.txt
ls: missing.txt: No such file or directory

You redirected stdout to out.txt, yet the error still appeared on screen — it travelled on stderr, which you did not redirect. out.txt will be empty. (Linux words the message slightly differently: cannot access 'missing.txt'. Same channel, same lesson.)

A third signal is invisible unless you ask: the exit code. Every command finishes with a number — 0 for success, anything else for failure. Ask for the last with echo $?.

ls missing.txt
echo $?
ls: missing.txt: No such file or directory
1

Two channels and a status line

Picture an instrument with a display and a separate fault LED. Stdout is the display, stderr is the fault LED, and the exit code is the status pin a controller reads to decide whether to continue. Automated systems read that pin, not the display — which is why "it printed something" is never proof a command succeeded.

Windows

> and 2> work in PowerShell, but echo $? does not: PowerShell's $? is True/False and the numeric code is $LASTEXITCODE.

Help and history

You do not memorise commands; you interrogate them. Most modern tools answer --help with a usage summary: the shape of the command and the flags it accepts.

node --help

The classic macOS/Linux utilities (ls, cp, mv, rm) predate that convention; on macOS, cp --help prints an illegal option complaint and a usage line instead. For those use the manual: man cp opens a scrolling page — space to scroll, q to quit, the most common "how do I get out of here?" moment for beginners. (PowerShell: Get-Help cp.)

The shell also remembers what you ran. Up arrow recalls the previous command, history prints recent commands numbered, and Ctrl+R reverse-searches them by any fragment. History is how you reconstruct what you actually did when something breaks.

Walkthrough: five operations, each one verified

Work in a disposable folder so nothing valuable is at risk:

cd ~/fullstack-journey
mkdir cli-practice
cd cli-practice

echo prints its argument to stdout; > sends that stdout into a file instead of the screen.

echo "pump 3 replaced seal" > log.txt
cat log.txt
pump 3 replaced seal

cat prints a file's contents to stdout. Now copy, rename, and inspect:

cp log.txt log-backup.txt
mv log-backup.txt archive.txt
ls -l
-rw-r--r--  1 you  staff  21 Aug  3 10:14 archive.txt
-rw-r--r--  1 you  staff  21 Aug  3 10:13 log.txt

cp copies (the original stays), mv moves or renames — renaming is moving to a new name in the same folder. Both files are 21 bytes: 20 characters plus the newline echo added. The -l flag turned a list of names into evidence. Now count lines, then delete:

wc -l log.txt
rm archive.txt
ls
       1 log.txt
log.txt

`rm` has no undo

rm deletes immediately — no Trash, no Recycle Bin, no recovery. Never run it on a path you have not read twice, and never with a wildcard you have not first tested by running ls on the same pattern. Everything above happens inside throwaway cli-practice for that reason.

Checkpoint

Point at any line above and say which part is the command, which is a flag, and which is the argument — and whether the output came from stdout or stderr.

Working with AI today: pair mode

Day 3 was human-only. Today's mode is pair — AI as a pair programmer, not a vending machine: it proposes, you verify. The rule that makes this safe is inspect the change, run your checks, and be able to explain the behaviour before accepting anything an AI produces. Not "it looked plausible". Accept nothing you cannot narrate line by line.

Pair mode, during your practice

"Give me one command at a time to practice file operations. Wait for me to explain the expected effect before showing the answer." Predict first, run it, then compare. If your prediction was wrong, that gap is the lesson.

Your turn

Build cli-log.md, recording each command and its effect in your own words.

  1. In ~/fullstack-journey/cli-practice, create a.txt and b.txt. Confirm with ls.
  2. Put text in a.txt with echo "..." > a.txt; confirm with cat a.txt.
  3. Copy a.txt to a-copy.txt with cp, then rename it to b-final.txt with mv. Confirm with ls -l — check the byte size matches the original.
  4. Run something you know will fail, like cat nope.txt. Record the exact error text and the result of echo $?.
  5. Pick a command you have never used — head, tail, or du — and run --help or man on it before running it. Write one sentence on what it does, from the docs, in your words.
  6. Run history, find the step 3 commands, and re-run one using the up arrow.
  7. Delete the practice files with rm and confirm with ls.
  8. Write cli-log.md in ~/fullstack-journey: one line per command, its flags and arguments named, and the effect you observed.

You are done when

cli-log.md exists and someone who has never used a terminal could read it and predict what each command does. That artifact — not a screenshot, not a copied answer — proves today is finished.

Common pitfalls

  • Confusing a flag with an argument. rm -r notes removes the folder notes recursively; rm -r alone does nothing. The dash tells you which is which.
  • Assuming silence means failure. cp and mv print nothing on success. Verify with ls, not by staring at an empty line.
  • Scrolling past the error. It names the file and the reason. Read it word by word first.
  • Expecting --help everywhere. BSD tools on macOS often reject it; reach for man.

Verify it yourself

Open today's reference, MDN's Command line crash course, and find where it explains command options and arguments.

  1. MDN describes at least one command this lesson did not cover. Pick one, read only the docs, write what it does in cli-log.md, then run it and check you were right.
  2. Which of "flag", "option", and "switch" does MDN prefer? Note it — different docs use different names for the same thing, and recognising that is part of reading docs fluently.

The hour

  1. 0–5 min Recall

    Without notes, state yesterday’s main idea and one unresolved question.

  2. 5–20 min Learn

    Read only the listed concept notes and official reference sections needed today.

  3. 20–48 min Build

    Create, copy, rename, inspect, and safely delete sample text files. Use --help before one unfamiliar command.

  4. 48–55 min Explain and verify

    Run the result, inspect evidence, and explain the data/control flow in your own words.

  5. 55–60 min Quiz and commit

    Complete the quiz, record one lesson, and commit the verified change when applicable.

What to hand in

Deliverable

A cli-log.md listing each command and its effect in your own words.

Working with AI today

AI as pair programmer

Define one small task, review the plan, inspect the diff, run checks, and explain every changed section.

Give me one command at a time to practice file operations. Wait for me to explain the expected effect before showing the answer.

References

End-of-day quiz

Q1 In a command, what is usually a flag?
Q2 Which result best proves today’s work is complete?
Q3 Before accepting an AI-generated code change, what should you do?

Explain-back gate

Pass the quiz above to unlock completion.

Quiz + explain-back checks required.