Where documentation lives
A command you type can be one of three kinds of thing: a shell builtin that bash runs itself, a shell keyword such as if, or an external program stored as a file somewhere on $PATH. Each kind has a different home for its documentation. Builtins and keywords are documented by bash, and you read them with the help builtin. External programs are usually documented in man pages, and many GNU programs also have longer info manuals. Nearly every program also prints a usage summary when you pass --help.
Before you look anything up, find out which kind of thing you have. The type builtin does this:
type printf
type time
type -a echoThe output in the lab is printf is a shell builtin, then time is a shell keyword, and for type -a echo, two lines: echo is a shell builtin followed by echo is /bin/echo. The last case matters. Bash runs its own echo at the prompt, but the external program /bin/echo also exists and is the one you get if you run it by its full path or from a script started by another shell. Knowing this tells you that help echo describes the builtin, and man 1 echo describes the program.
Man page sections
A man page belongs to one of several numbered sections. The same name can exist in more than one section, and the number tells you which kind of thing it documents. The standard sections on Linux are:
| Section | Covers | Example |
|---|---|---|
| 1 | User commands (executable programs and shell utilities) | man 1 ls |
| 2 | System calls, the kernel interface | man 2 openat |
| 3 | Library functions, mostly the C library | man 3 printf |
| 4 | Special files, such as device files | man 4 tty |
| 5 | File formats and configuration files | man 5 passwd |
| 7 | Overviews, conventions, and miscellany | man 7 pty |
| 8 | System administration commands | man 8 mount |
The classic example is printf. Section 1 documents the printf command you run in a shell, and section 3 documents the C library function printf(3) that programs call. Both pages are correct for their own purpose. When you write man printf with no section, man shows the first match in its search order, which is usually section 1. Write the section number explicitly when you mean the other one. The same convention appears in documentation as printf(3), which means "the page printf in section 3".
Reading the SYNOPSIS
Every man page has a SYNOPSIS section that gives the syntax in a compact notation. Learning the notation is more useful than memorizing the options. The common symbols are:
[ ]marks something optional, such as[OPTION]....after an item means it can be repeated, as in[FILE]....|separates alternatives. You pick one side.- Bold text or capitalized words such as
FILEstand for a value you supply, and-or--prefixes are literal.
So ls [OPTION]... [FILE]... means that you can give zero or more options and then zero or more file names. In the lab, you can get the same information from the program itself with --help, which is covered below.
Navigating a man page
On a normal system, man opens the page in less, a pager. The keys are the ones to learn:
- Space and b move a page forward and back.
- / followed by a pattern searches forward, and n jumps to the next match.
- g and G go to the top and bottom.
- q quits and returns you to the prompt.
To find a page when you only know a topic, use man -k or its equivalent apropos. Both search the one-line NAME descriptions of every page:
man -k copy
apropos copyThe results are lines such as cp (1) - copy files and directories, which tell you the name and section to open next. whatis ls prints only the one-line description of a single page.
info manuals and --help
Many GNU projects maintain longer manuals in the info format, which has its own reader. Its navigation keys are different: n and p move to the next and previous node, u goes up one level, and Enter follows a link. The coreutils manual, which covers ls, cp, and friends, is written as info and is also published online at gnu.org. Reading the online version is often faster than the terminal reader.
For a quick reminder of the options, --help is the fastest route. It prints a usage line and a list of options, and it does not open a pager:
ls --help | head -n 6Be careful with -h. It is not a universal help flag. In du and ls it means human-readable sizes, and in other programs it means something else again. Use --help to get help.
Bash builtins: the help command
Man pages do not document builtins like cd. Bash documents them itself, through the help builtin. It prints the syntax and a description:
help cd
help -d cd
help -s cdhelp cd prints the full description. help -d cd prints only the one-line summary. help -s cd prints only the synopsis line. These flags exist in bash 5, and they are the fastest way to check the syntax of a builtin. The reference for everything else bash does is the bash(1) man page, whose section named SHELL BUILTIN COMMANDS is the long form of the same material. The GNU Bash Reference Manual online is the same content in a readable form.
In this lab: no man or info
The lab image does not include the man or info programs, and it does not include the man page files. They were removed to keep the image small. Typing man ls here fails with a "command not found" error. This is common on real systems too: minimal containers and embedded images often ship without documentation, so learning to work without it is a useful skill.
In the lab, use these instead: --help for external programs, help for builtins, type to identify what you are running, and the online pages at man7.org for the full text of a Linux man page. Once you have the page open, the section and notation rules above apply unchanged. On a real machine, the same commands work with man in front of them.