Skip to content
Tutorials Center
My learning

Topics

Lesson 95 of 95 ยท Reference overview

Linux Command Reference: A Map of Commands by Task

A map of the Linux commands you need, grouped by task, with a guide to reading synopses, option conventions, exit statuses and finding the right command.

A tutorial teaches you in a sequence: each lesson builds on the one before. A reference answers a different question, the one you ask at 3 p.m. with a deadline: "What was the option that does X?" It is organized by command, it is short, and it expects you to know the basics already. This page is the starting point for using command-level reference material. It explains how a command description is built, how to read the compact notation in a synopsis, what conventions nearly all commands share, and it gives you a map of commands by task that links back to the lessons that teach each group.

Once you can read a synopsis and know where a command comes from, an unfamiliar tool stops being intimidating. You can run the three examples below in the browser: one about option conventions, one about what kind of thing a "command" is and how it reports success, and one that builds a tiny searchable command database in the spirit of apropos.

Anatomy of a command description

Every well-organized reference entry has the same parts, and so do the manual pages (man) on your machine:

Part Question it answers
Name What is it, in one line?
Synopsis What shapes can the command line take?
Description What does it do, and what are the key ideas?
Options What does each flag change?
Operands What do the non-option arguments mean (files, patterns, hosts)?
Exit status How does it report success and failure?
Examples What do common uses look like?
Pitfalls and see also What goes wrong, and what is related?

The synopsis uses a small notation that is worth memorizing, because it appears in every manual:

Notation Meaning Example
[ ] optional ls [OPTION]... [FILE]...
... may be repeated cp SOURCE... DIRECTORY
a | b choose one sort [-n | -h]
UPPERCASE or <angle> placeholder you replace with a real value head -n NUM FILE
-- end of options; what follows is an operand rm -- FILE
- as an operand standard input (or output) cat -

Read grep [OPTION]... PATTERNS [FILE]... aloud: "grep, any number of options, then the patterns, then any number of files." If you leave the files out, grep reads standard input, which is how it works in a pipeline. The notation gives away behavior that the description repeats in words.

Option conventions

Most commands follow the same habits, so once you know them you can guess correctly about tools you have never used:

  • Short options are one letter after a single dash: -l, -a. They can be bundled: -la equals -l -a.
  • Long options use two dashes and a word: --all, --human-readable. A value is attached with = (--lines=2) or given as the next word.
  • A short option that needs a value accepts it attached or separate: -n 2 and -n2 are the same.
  • -- ends option parsing. After it, everything is an operand. This is how you handle a file named -report.txt.
  • - as a file name usually means standard input.
  • GNU tools let you put options after the operands (ls dir -l); strict POSIX mode does not. Do not rely on it in portable scripts.
Bash Option conventions in action

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The rm -report.txt experiment shows why -- matters: rm parses -r, -e, and complains about -e. That same trap is behind many "I deleted the wrong thing" stories, and it is why scripts write rm -- "$file" when $file comes from outside. See Quoting and Expansion for the other half of that habit.

What is a "command"? Where does the name resolve?

When you type ls, Bash has to decide what that word means. It checks in a fixed order, and knowing the order explains many surprises (why echo behaves differently in two shells, why your function shadows a program, why a new tool is "not found"):

flowchart TD
  A["You type a word, for example: ls"] --> B{"Reserved word?<br/>if, while, case..."}
  B -- "yes" --> R["Part of shell syntax"]
  B -- "no" --> C{"Alias?"}
  C -- "yes" --> R2["Replace by the alias text"]
  C -- "no" --> D{"Shell function?"}
  D -- "yes" --> R3["Run the function"]
  D -- "no" --> E{"Builtin?<br/>cd, echo, type..."}
  E -- "yes" --> R4["Run inside the shell"]
  E -- "no" --> F["Search each PATH directory in order"]
  F --> G["Run the first match, or fail with status 127"]

The lookup order of a command name in Bash.

The builtin type reveals the answer, and command skips functions and aliases. Alongside, every command ends with an exit status: 0 means success and anything else is a failure, with some conventions that are worth knowing by heart (grep returns 1 for "no match" but 2 for a real error). Scripts built on Exit Codes, set -e and Error Handling depend on them:

Bash What kind of command is it, and how did it end?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Two numbers in that list are the ones to remember when debugging: 127 means "the command could not be found" (a typo, or a PATH problem), and 126 means "found, but not executable" (a permission problem, see File Permissions and Ownership). A status above 128 usually means "killed by signal number (status minus 128)", which connects to Signals and trap.

A map of commands by task

Think in tasks, not alphabetical lists. This table groups the commands you will use most and points to the lesson that teaches each group.

Task Commands Where to learn them
Get help man, --help, help, type, apropos, info Getting Help
Move around and look pwd, cd, ls, tree, file, stat Navigation, The Filesystem Layout
Create, copy, move, delete touch, mkdir, cp, mv, rm, ln Creating Files, Copying, Moving and Deleting, Links
Match many files globs, find, locate, xargs Globbing, find and locate, xargs
Read text cat, less, head, tail, wc, nl Viewing Text
Search and transform text grep, sed, awk, cut, sort, uniq, tr, diff, patch grep, Regular Expressions, sed, awk, sort, uniq, cut, diff and patch
Connect commands pipes, redirection, here-documents, subshells Streams, Pipes, Here-Documents, Subshells
Permissions and users chmod, chown, umask, sudo, id, useradd File Permissions and Ownership, Users, Groups and sudo
Archives and disk space tar, gzip, zip, df, du Archives and Compression, Disk Usage
Processes ps, top, kill, jobs, nice, nohup Processes, Jobs and Background Processes, Signals
System and services apt, dnf, systemctl, journalctl, mount, lsblk Packages, Services and systemd, Disks, Mounts, Logs and Monitoring
Network and remote work ip, ss, ping, curl, ssh, scp, rsync Networking Basics, SSH, scp and Working Remotely
Scripting test/[[ ]], read, printf, date, trap, set Your First Script, Conditionals, printf and date

Beyond the table, the cheat sheet is the one-page version, and the interview questions test what sticks.

Command families you will meet

A few families of commands share a design, which makes them easier to remember as a group:

  • Filters read lines from standard input and write transformed lines to standard output: grep, sed, awk, sort, uniq, cut, tr, head, tail. They are the vocabulary of pipelines (Building Text Pipelines).
  • Commands with subcommands use the shape tool SUBCOMMAND [OPTIONS]: git commit, systemctl status, apt install, ip addr. The subcommand is the real command name; global options usually come before it.
  • Commands that talk to the kernel's pseudo files: ps, free and uptime just read /proc, which is why you can reproduce them with cat and awk (the idea behind Project: Server Health Monitor).
  • Administrative tools such as useradd, mount, iptables and fdisk need root rights and live in sbin directories; the manual section number for them is 8.

Finding the right command

You often know the task but not the name. The tools, from fastest to deepest:

  1. command --help or help builtin_name: a short usage text, no pager.
  2. man command: the full manual. Inside the pager, /word searches, n jumps to the next hit, q quits. Sections matter: man 5 passwd is the file format, man passwd the command.
  3. man -k word or apropos word: search the one-line descriptions of all installed manual pages. That is the answer to "what is the command that does X?".
  4. type -a name and command -v name: show where a name comes from and which copy runs first.
  5. info coreutils or the online manuals for GNU tools, which are longer and more narrative than man pages.

apropos is simple at heart: a database of "name - description" lines, searched for words. We can build a small one ourselves, which also makes a handy personal cheat sheet:

Bash A tiny apropos for your own command notes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Real apropos works on the same principle, but its database is built from the NAME line of every installed manual page (mandb refreshes it). That is also why the first sentence of a manual page is written to be searchable.

Differences between systems

Not every system has the same implementation behind a command name:

Family Typical systems Notes
GNU coreutils and friends Debian, Ubuntu, Fedora, Arch Many long options, options after operands, sed -i, grep -P, date -d.
BSD tools macOS, FreeBSD sed -i '' needs an argument, stat -f instead of stat -c, no readlink -f on older systems.
BusyBox Alpine Linux, containers, routers One small binary offering reduced versions of hundreds of commands; fewer options.

The lessons on this site use GNU tools and Bash. When a script must run elsewhere, read Portability, test the target with --version, and prefer the common subset of options. A script can detect the flavor without guessing:

Terminal
if sed --version >/dev/null 2>&1; then
  echo "GNU sed"
else
  echo "not GNU sed (BSD or BusyBox)"
fi

Small commands worth knowing: namei, whereis, stat, stty and pidof

Some small commands never get a lesson of their own, yet they answer exactly the questions that eat time in real work. Here are the ones to remember, with one-line reasons:

Command Answers Example
namei path "Which step of this path is a link, or unreadable?" It lists every component with its type; -m adds permissions and -l adds owners. namei -m /var/www/html/index.html
whereis cmd Where are the binary, source and manual page of cmd? Use -b for the binary only. whereis -b ls
stat file Size, inode, links, permissions, owner and all three timestamps. -c FORMAT picks fields for scripts. stat -c '%s bytes, mode %a' file
stty Read or change terminal settings: stty -a lists them, stty size prints rows and columns, stty -echo hides typed text (password prompts), stty sane repairs a broken terminal. stty size
pidof name PIDs of the processes with that exact program name. pgrep -x name is the more widely available equivalent. pidof sshd

namei is the tool for "Permission denied" mysteries: access needs the execute bit on every directory along the way, and namei -m shows which one lacks it. stat -c is safer than parsing ls -l, with format codes such as %n (name), %s (size), %a (octal mode), %A (mode string), %F (file type), %U (owner), %Y (modification time as epoch seconds) and %N (a link with its target). stty and pidof need a real terminal or a running service, so only the first three run below:

Bash namei, whereis and stat

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

For stty on a real terminal:

Terminal
stty size        # prints "rows columns", for example: 40 120
stty -echo; read -r secret; stty echo   # read without showing the typing
stty sane        # restore a terminal left in a strange state

Always restore echo afterwards, ideally with a trap (see Traps and Signals), or the user's terminal stays silent after an interrupted script.

Habits for using any reference

  • Read the synopsis first, then the one option you need. Do not read the whole page.
  • Try it on a copy. Run the command with a harmless test file (or add -n, --dry-run or echo in front) before pointing it at real data.
  • Check the exit status (echo $?) when scripting; never assume success.
  • Prefer long options in scripts. --recursive explains itself in six months; -R versus -r may not.
  • Quote variables and use -- whenever a value might begin with a dash or contain spaces.
  • Keep your own notes. The mini database above is a seed: add the commands and options that you keep looking up.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In the synopsis cp [OPTION]... SOURCE... DIRECTORY, what do the square brackets and the three dots tell you?

    Square brackets mean optional, and an ellipsis means the item can be repeated. DIRECTORY has no brackets, so it is required.
  2. 2. You have a file called -report.txt. Which command removes it safely?

    Quotes do not stop the command from seeing a leading dash. The double dash ends option parsing, so the next word is treated as a file name.
  3. 3. A command exits with status 127. What does that usually mean?

    127 is 'command not found'. A found-but-not-executable program gives 126, and Ctrl-C ends a program with status 130.
  4. 4. grep -q word file exits with 1. What is the most precise reading?

    For grep, 0 means a match was found, 1 means no match, and 2 means an error such as a missing file.
  5. 5. Which tool answers 'which command does X?' by searching the one-line descriptions of the installed manual pages?

    apropos and man -k search the NAME lines of the manual pages. type and which only locate a command whose name you already know.

Summary

  • A reference entry has a name, synopsis, description, options, operands, exit status, examples and pitfalls. The synopsis notation uses [ ] for optional, ... for repeatable, | for alternatives and -- for the end of options.
  • Short options can be bundled (-la), long options use --name and =, -- ends option parsing, and - usually means standard input. GNU tools accept options after operands; portable scripts should not.
  • Bash resolves a name as reserved word, alias, function, builtin, then the first match in PATH. type -t tells you which; command skips functions and aliases.
  • Exit status 0 is success; grep and diff use 1 for a normal "no match" or "differs"; 126 means not executable, 127 not found, and above 128 a signal.
  • Use the task map above to find the lesson for each group of commands, and man -k or apropos when you know the task but not the name.
  • Commands differ between GNU, BSD and BusyBox systems; test, quote, use --, and keep personal notes for what you look up often.

Next: Linux and Bash Cheat Sheet