Man Pages & Getting Help
Four types of commands, the manual system, and how to answer your own questions
Quick check before you start: Do you know the difference between
cdand/usr/bin/ls? If not, read on. If you can explain which is a builtin and which is an external program, skip to Man Page Structure.Practice this topic: Man Pages skill drill
After this lesson, you will be able to:
- Identify the four types of shell commands using
typeandwhich - Navigate a man page (scroll, search with
/, quit withq) - Explain man page sections (1 = user commands, 3 = C library functions)
- Use
man -kto search for commands by keyword
Four Types of Commands
Not every command works the same way. The shell recognizes four types:
- Executable programs — compiled binaries in
/usr/bin,/bin, etc. (ls,cp,gcc) - Shell builtins — built into bash itself (
cd,echo,exit) - Shell functions — user-defined mini scripts
- Aliases — shortcuts (
llis often aliased tols -la)
Use type to find out what a command is:
type cd
# cd is a shell builtin
type ls
# ls is /usr/bin/ls
type ll
# ll is aliased to 'ls -la'
Use which to find where an executable lives on disk:
which gcc
# /usr/bin/gcc
which cd
# (no output — cd is a builtin, not a file)
type works on all four kinds. which only finds executables in your PATH. If you need to know what kind of command something is, use type. If you need to know where on disk a program lives, use which.
Man Page Structure
The man command opens the manual page for any documented command:
man ls
Man pages follow a standard structure:
| Section | Content |
|---|---|
| NAME | Command name and one-line summary |
| SYNOPSIS | Syntax — brackets [ ] mean optional, ... means repeatable |
| DESCRIPTION | What the command does |
| OPTIONS | Every flag explained |
| EXAMPLES | Usage examples (not always present) |
| SEE ALSO | Related commands |
Navigating Inside a Man Page
Man pages open in a pager (usually less). The controls:
| Key | Action |
|---|---|
Space / f |
Page forward |
b |
Page back |
/pattern |
Search forward for pattern |
n |
Next search match |
q |
Quit |
Man Page Sections
The manual is divided into numbered sections:
| Section | Contains | Example |
|---|---|---|
| 1 | User commands | man 1 ls |
| 2 | System calls | man 2 open |
| 3 | C library functions | man 3 printf |
| 5 | File formats | man 5 passwd |
| 8 | Admin commands | man 8 mount |
Section 3 matters for this course. When you start writing C, man 3 printf shows the C library function, not the shell command. If a name exists in multiple sections, specify the number:
man printf # shows the shell command (section 1)
man 3 printf # shows the C library function
Searching for Commands
When you know what you want to do but not which command does it, use man -k:
man -k "copy files"
# cp (1) — copy files and directories
This searches the one-line descriptions (the NAME section) of every man page. The --help flag is another option — most commands support it:
ls --help
--help gives a shorter summary than the full man page. Use it when you just need a flag reminder.
echo is a shell builtin or an external program. Which command gives you that answer?type reports whether a command is a builtin, executable, alias, or function. which only searches PATH for executables — it does not identify builtins. man echo shows documentation for the external /usr/bin/echo, which does not tell you that bash has its own builtin version.
What Comes Next
You can now find help for any command on the system. Next, you will learn how Unix controls who can read, write, and execute files.