Chapter 16: Bash Manual (man)
What is man? (super simple first)
man = manual It opens the official built-in documentation (called “man page”) for almost any command, function, file format, or system call in Linux.
Think of it as the help book that lives inside your terminal — no internet needed!
Most powerful thing: every good Linux command has a man page. Even man itself has one — that’s how you learn how to use it!
1. Basic usage (start here)
|
0 1 2 3 4 5 6 7 8 9 |
man ls man mkdir man touch man cd |
What happens?
- Terminal clears and shows a long text document
- You are now inside a pager (usually less program)
- It shows detailed info about the command
2. Typical structure of a man page (very important — memorize this pattern)
Almost every man page has these sections (in this order):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
NAME Short name + one-line description SYNOPSIS How to write the command (syntax) — very important! DESCRIPTION Long explanation what it does OPTIONS Every flag (-l, -a, --color etc.) explained EXAMPLES Real usage examples (gold mine!) EXIT STATUS / RETURN VALUE What numbers mean success/failure SEE ALSO Related commands BUGS / AUTHORS / COPYRIGHT (sometimes) |
Pro tip from experienced users: When you open a man page → immediately scroll to EXAMPLES section — most people learn fastest from examples.
3. How to move around inside man page (navigation keys — learn these!)
You are inside less (or sometimes more), so use these keys:
| Key / Combination | What it does | Very useful when… |
|---|---|---|
| ↑ / ↓ or j / k | Scroll line by line | Reading slowly |
| Space / Page Down | Next page | Skip quickly |
| b / Page Up | Previous page | Go back |
| /something | Search forward for “something” | Find -r option fast |
| ?something | Search backward | |
| n | Next search result | After / or ? |
| N | Previous search result | |
| g | Go to top of page | Start over |
| G | Go to bottom of page | Jump to EXAMPLES or SEE ALSO |
| q | Quit / exit man page | Finish reading |
| h | Show help (all keys) | Forgot something? Press h |
Real trick — to jump straight to EXAMPLES:
- Open man ls
- Press G (capital G) → go to end
- Press ?EXAMPLES then Enter → search backward for “EXAMPLES”
- Or just /EXAMPLES and n/n until you find it
4. Most useful options for man itself
|
0 1 2 3 4 5 6 |
man man # Read manual about man — do this first! |
Common useful flags:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
man -k mkdir # search man pages for keyword "mkdir" (like apropos) man -k "make directory" # find commands related to phrase man -f ls # short whatis description (one line) man ls # normal man 1 ls # force section 1 (user commands) — usually default man 2 mkdir # section 2 — system call version of mkdir (rare for beginners) man -a printf # show ALL man pages named printf (shell builtin + C function) man -P cat ls # print whole man page to terminal (no pager) |
5. The 9 main sections of man pages (very useful knowledge)
Linux organizes man pages into numbered sections:
| Section | What it contains | When you need it | Example command |
|---|---|---|---|
| 1 | Executable programs / commands | Everyday commands (99% of time) | man 1 ls or just man ls |
| 2 | System calls (kernel functions) | C programming, low-level | man 2 fork |
| 3 | Library functions (C libs) | Programming | man 3 printf |
| 4 | Special files (/dev devices) | Hardware stuff | man 4 tty |
| 5 | File formats & configs | Config files like /etc/passwd | man 5 crontab |
| 6 | Games | Fun stuff | man 6 tetris (if installed) |
| 7 | Miscellaneous (protocols, macros, etc.) | Weird extras | man 7 regex |
| 8 | System admin commands & daemons | root / server stuff | man 8 iptables |
| 9 | Kernel routines (not common) | Very advanced | Rarely used |
Real example why sections matter:
|
0 1 2 3 4 5 6 7 |
man printf # shows shell builtin (section 1) man 3 printf # shows C library function (different!) |
6. Real-life examples you should try now
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 1. Learn ls completely man ls # Press G → then /EXAMPLES → Enter → read examples # 2. Find how to search man pages man -k copy # shows cp, install, etc. # 3. Bash itself (very long but powerful) man bash # Search for: / Brace → see {a..z} expansion # Or / Parameter → learn {var:-default} # 4. See short description only whatis mkdir # or man -f mkdir # 5. Print man page to file (useful sometimes) man mkdir > mkdir-help.txt # 6. Quick help without full man page ls --help # shorter than man ls mkdir --help |
7. Quick cheat-sheet table
| What you want | Command you type | Why it’s useful |
|---|---|---|
| Read manual for command | man ls | Main way |
| Learn about man itself | man man | Start here! |
| Search for keyword | man -k directory | Find unknown commands |
| Jump to examples | Inside man: G then /EXAMPLES | Fastest learning |
| Specific section | man 5 crontab | Config files |
| All versions of same name | man -a printf | See builtin vs library |
| One-line summary | whatis ls or man -f ls | Quick check |
| Search inside man page | /–color then n | Find specific option |
8. Bonus tips (what pros do)
- First time? → man man then man intro (great beginner intro!)
- Stuck? Press h inside man for help
- Prefer shorter help? Many commands have –help (faster than man)
- Want colorful man pages? Add to ~/.bashrc:
Bash01234567export MANPAGER="less -R"export LESS=-R
- Offline forever — man pages are local!
Now open your terminal and try:
|
0 1 2 3 4 5 6 7 |
man ls # scroll with space, search / -l , press q to quit |
Then tell me: did you find the EXAMPLES section? Or ask me: “how to search for all commands about files?” or “show me man page for bash loops” — I’ll guide you with exact steps! 😄
