ch00/l02

Command anatomy and help

Read commands as command, options, arguments, and input source.

man ls 20 min read, 20 min lab beginner

Most shell commands have a shape: the executable, options that change behavior, and arguments that name targets. The manual page is not trivia; it is part of the workflow. Operators memorize the shape and know where to verify flags.

In the field

You need a long directory listing sorted by time, but you do not trust a copied command from a forum.

Worked command

$ ls -lhtr /var/log# command: ls# options: -l -h -t -r# argument: /var/log$ man ls$ ls --help | sed -n '1,18p'
Anti-pattern

Do not copy flags you cannot explain when files or services are on the line.

Safer pattern

Parse the command first, then verify unknown options with man or --help.

Knowledge check

In `grep -rn "error" /var/log`, how does the command break down into executable, options, and arguments?

  • A grep is the executable, -rn are options, "error" and /var/log are arguments
  • B grep -rn is the executable, "error" is the option, /var/log is the argument
  • C grep is the executable, -rn and "error" are options, /var/log is the argument
  • D grep is the executable, "error" is the option, -rn and /var/log are arguments
Show the answer

Correct: A. grep is the executable, -rn are options, "error" and /var/log are arguments

Why

Options start with a dash and change behavior (-r recursive, -n line numbers); everything else is an argument, here the pattern "error" and the target /var/log. The pattern is a positional argument, not an option, even though it sits between the flags and the path.

Practice checklist

  1. Pick three commands from this page.
  2. Split each into executable, options, and arguments.
  3. Find one option in the manual for each command.

Deliverable evidence

  • Three annotated command shapes.
  • A note explaining one flag you looked up.
Teaching diagramch00 · mental model
read state, then act, then read the result1. prompt statewhoami / hostnamepwd / $SHELL2. command shapecmd -opts argsverify: man / --help3. exit statusecho $?0 ok / non-zero stopread stderr firstnon-zero?prompt theme shows, it does not prove

shows: The chapter's operator loop: read prompt state, parse the command into executable/options/arguments and verify it, run it, then read exit status and stderr before the next move.

does not prove: It does not prove a zero exit status means the intended effect happened, nor that the prompt's displayed host, path, or privilege are accurate; both must be confirmed with commands when consequences matter.

Memorize this

Commit these to memory, then drill them until recall is automatic.

man--helpcommand options arguments
Recall practice · Scenario -> next check

cue You copied a command with a flag you cannot explain and files are on the line. What do you do before running it?

show recall target

Parse it into executable/options/arguments, then verify the unknown flag with man or --help