The man command is one of the most fundamental, powerful, and misunderstood tools in Linux and Unix-like operating systems. It is not just a help command β it is a documentation system, database, formatter, and pager working together.
1. What Is the man Command?
man stands for manual.
It is a command-line interface to the Linux manual pages, which are structured documentation files describing:
- Commands
- System calls
- Library functions
- Configuration files
- File formats
- Kernel interfaces
Basic usage
man ls
This opens the official documentation for the ls command.
2. High-Level Architecture of man
The man system is not a single program.
It consists of multiple components:
User
β
man command
β
man-db / man-pages
β
Formatter (groff / troff)
β
Pager (less)
β
Terminal
Key components
| Component | Purpose |
|---|---|
man |
Front-end command |
man-db |
Manual page database & index |
man-pages |
Actual documentation content |
groff |
Formats documents |
less |
Displays formatted output |
3. Where Are Man Pages Stored?
Man pages live in predefined directories:
/usr/share/man/
/usr/local/share/man/
Each directory contains section subdirectories:
man1/
man2/
man3/
man4/
man5/
man6/
man7/
man8/
Example:
/usr/share/man/man1/ls.1.gz
4. Man Page Sections (VERY IMPORTANT)
Every man page belongs to a section.
Complete section list
| Section | Description |
|---|---|
| 1 | User commands |
| 2 | System calls |
| 3 | C library functions |
| 4 | Special files (devices) |
| 5 | File formats |
| 6 | Games |
| 7 | Miscellaneous |
| 8 | System administration |
Example
man 2 open
man 3 printf
man 5 passwd
5. How man Finds a Page (Internal Logic)
When you run:
man ls
Internally, man:
- Reads configuration from
/etc/manpath.config - Determines search paths
- Checks the man database
- Searches sections in priority order
- Selects best match
- Decompresses
.gz - Formats content
- Pipes output to pager
6. Man Page Compression
Man pages are usually compressed:
ls.1.gz
man automatically handles:
- gzip (
.gz) - bzip2 (
.bz2) - xz (
.xz)
You never decompress manually.
7. Full Syntax of man
man [OPTIONS] [SECTION] PAGE
Examples
man ls
man 5 passwd
man -k printf
8. Essential man Options (Complete List)
Display options
man -a ls # Show all matching pages
man -f ls # Short description (whatis)
man -k socket # Search keyword
Formatting options
man -P less
man -T pdf ls
man -T html ls
Path options
man -w ls # Show file location
man -W ls # All matching locations
Locale & encoding
man -L en ls
man --encoding=UTF-8 ls
9. Searching Inside Man Pages
Using pager search
Inside man:
/word
n (next)
N (previous)
Keyword search
man -k network
This uses the man database index.
10. The whatis and apropos System
These commands are wrappers around man indexing.
whatis ls
apropos socket
Internally:
man -f
man -k
11. Man Page Database (mandb)
Man pages are indexed for fast lookup.
Rebuild database
sudo mandb
Database location
/var/cache/man/
12. Man Page Output Pipeline (Deep Internals)
man
β
zcat / bzcat
β
groff -Tutf8 -man
β
less
Formatter
groff
Pager
less
You can override pager:
MANPAGER=cat man ls
13. Man Page Structure (Standard Layout)
Every man page follows a strict format:
NAME
SYNOPSIS
DESCRIPTION
OPTIONS
RETURN VALUE
ERRORS
FILES
EXAMPLES
SEE ALSO
Example
man open
14. Viewing Raw Man Source
man -l /usr/share/man/man1/ls.1.gz
Or:
zcat ls.1.gz
15. Writing Your Own Man Page (FULL)
File name
mycmd.1
Basic structure
.TH MYCMD 1
.SH NAME
mycmd \- example command
.SH SYNOPSIS
mycmd [OPTIONS]
.SH DESCRIPTION
This is a test command.
Install it
sudo cp mycmd.1 /usr/share/man/man1/
sudo mandb
View
man mycmd
16. Man Page Macros (IMPORTANT)
Man pages use troff macros:
| Macro | Meaning |
|---|---|
.TH |
Title |
.SH |
Section header |
.B |
Bold |
.I |
Italic |
.TP |
Tagged paragraph |
Example:
.B -h
Show help
17. Exporting Man Pages
man -Tpdf ls > ls.pdf
HTML
man -Thtml ls > ls.html
18. Debugging Man Pages
man -d ls
Shows:
- Paths searched
- Sections matched
- Format pipeline
19. Configuration Files
Global config
/etc/manpath.config
Controls:
- Search paths
- Section order
- Locale behavior
20. Environment Variables Used by man
| Variable | Purpose |
|---|---|
MANPATH |
Override search paths |
MANPAGER |
Custom pager |
LESS |
Pager behavior |
LANG |
Localization |
Example:
export MANPAGER="less -R"
21. Common Problems & Solutions
Man page not found
sudo mandb
Wrong section shown
man 2 open
Pager issues
export MANPAGER=cat
22. Why man Still Matters
- Always available (offline)
- Official documentation
- Exact system behavior
- Matches installed version
- No external dependency
If you master man, you master Linux documentation.
23. Final Thoughts
The man command is:
- A documentation framework
- A searchable database
- A formatting pipeline
- A learning system
It is not beginner-friendly by accident β it is precise by design.
If you understand man, you understand how Unix systems document themselves.
Author
Farhad Rahimi Klie
Top comments (0)