Command Help — Asking the System Itself
Nobody remembers every option of every command. Experienced Linux users aren't people who know everything. They're people who know how to look things up in seconds, without leaving the terminal. The documentation is already installed, and you just need to know how to reach it.
The rule
Ask the command first: --help for a glance, man for the full story.
--help prints a short summary straight to the terminal. Most GNU commands support it:
$ sort --help
Usage: sort [OPTION]... [FILE]...
-n, --numeric-sort compare according to string numerical value
-r, --reverse reverse the result of comparisons
...man opens the full manual page:
$ man sortThe page opens in a pager (usually less), and a few keys are all you need:
| Key | Does |
|---|---|
Space / b |
page down / back |
/word |
search for "word"; n goes to the next match |
q |
quit |
Manual pages are split into numbered sections, and the section number appears in brackets, as in passwd(1):
| Section | Holds |
|---|---|
| 1 | user commands |
| 5 | file formats, such as config files |
| 8 | administration commands |
So man passwd shows the passwd command, and man 5 passwd shows the format of the /etc/passwd file.
Don't know the command's name? Search the short descriptions of every manual page:
$ man -k compress # same as: apropos compress
gzip (1) - compress or expand files
...Shell builtins such as cd and export are part of the shell itself, so they may not have their own man page. In Bash, help cd explains them. type cd tells you whether something is a builtin.
The shortcut
Climb one rung at a time: --help first, then man, then man -k. Start with the quick answer and only go deeper if you need to.
Glance
sort --helpmentions-tfor the separator and-kfor the key, but not how to combine them.
Two traps. man shows the manual for the version installed on this machine, which can differ from what a website describes, and that's a good reason to trust it. And typing man cd in Bash may show a general builtins page or nothing, because cd is built into the shell. Use help cd instead.
Drills
Answer fast — trust the rule.
What is the quickest way to see a short list of tar's options in the terminal?
Inside a man page, how do you search for the word "recursive"?
You want the format of the /etc/passwd file, not the passwd command. Which command shows it?
You need a command that makes archives but don't know its name. What's the best start?
Remember
- Ask the command first:
--helpfor a glance,manfor the full story. - Climb one rung at a time:
--help, thenman, thenman -kwhen you don't know the name. - In a man page,
/searches andqquits. Usehelpfor shell builtins likecd.
