Skip to main content

Linux Man Pages: How to Teach Yourself Any Command

·1449 words·7 mins
Linux Learning Lab
Author
Linux Learning Lab
Writing about code, tools, and workflows.
linux-beginner - This article is part of a series.
Part 6: This Article

What Are Man Pages?
#

Man pages (manual pages) are the built-in documentation system on Linux. Nearly every command, system call, library function, and configuration file has a man page explaining what it does, how to use it, and what options it accepts.

When you don’t know how a command works — or you know the command but forgot a specific flag — the man page is where you look first. It’s available offline, on any system, without a browser.

man ls

That opens the full manual entry for ls. You’re now reading documentation written by the people who built the tool.

Opening and Navigating Man Pages
#

Man pages open in a pager — usually less. If you’ve used less before (or Vim), the navigation will feel familiar:

KeyAction
Space / fPage down
bPage up
j / kScroll down / up one line
/patternSearch forward
?patternSearch backward
nNext search result
NPrevious search result
qQuit
gGo to beginning
GGo to end

Searching within a man page
#

If you’re looking for a specific option, search for it:

/--recursive

This jumps to the first occurrence. Press n to cycle through matches.

Man Page Sections
#

Man pages are organized into numbered sections. This matters because the same name can exist in multiple sections with completely different meanings.

SectionContentsExample
1User commandsls, grep, git
2System callsopen, read, fork
3Library functionsprintf, malloc, strlen
4Special files and devices/dev/null, /dev/random
5File formats and config filespasswd, crontab, fstab
6Gamesfortune, cowsay
7Miscellaneousascii, regex, signal
8System administration commandsmount, iptables, useradd

Why sections matter
#

Consider crontab:

man crontab       # Section 1 — the crontab command (how to edit your crontab)
man 5 crontab     # Section 5 — the crontab file format (syntax of the schedule)

Or passwd:

man passwd        # Section 1 — the passwd command (changing passwords)
man 5 passwd      # Section 5 — the /etc/passwd file format (fields and structure)

Or printf:

man printf        # Section 1 — the shell printf command
man 3 printf      # Section 3 — the C library printf() function

If you open a man page and it’s not what you expected, you’re probably looking at the wrong section.

Specifying a section
#

man 2 open        # The open() system call
man 3 sleep       # The C sleep() function (not the shell command)
man 5 fstab       # The fstab file format
man 8 mount       # The mount command (system administration)

Listing all available sections for a name
#

man -f crontab
# crontab (1)          - maintain crontab files for individual users
# crontab (5)          - tables for driving cron

# Equivalent command:
whatis crontab

Structure of a Man Page
#

Most man pages follow a standard layout:

SectionContents
NAMECommand name and one-line description
SYNOPSISUsage syntax — how to invoke it
DESCRIPTIONDetailed explanation of what it does
OPTIONSList of flags and arguments
EXAMPLESUsage examples (not all pages have this)
FILESRelated files (config files, log locations)
EXIT STATUSWhat return codes mean
SEE ALSORelated man pages
BUGSKnown issues
AUTHORWho wrote it

Not every man page has every section, but NAME, SYNOPSIS, DESCRIPTION, and OPTIONS are almost always present.

Reading the SYNOPSIS
#

The SYNOPSIS tells you how to invoke a command. It uses formatting conventions to show what’s required, what’s optional, and what can be repeated:

ls [OPTION]... [FILE]...
FormatMeaning
UPPERCASEA placeholder — substitute your own value
[brackets]Optional
...Can be repeated
`ab`
bold or literalType exactly as shown

So ls [OPTION]... [FILE]... means:

  • ls — the command itself (required)
  • [OPTION]... — zero or more options (all optional)
  • [FILE]... — zero or more filenames (optional; defaults to current directory)

A more complex example:

cp [OPTION]... SOURCE... DEST
cp [OPTION]... -t DIRECTORY SOURCE...

This shows cp has two forms. In the first, you provide one or more source files and a destination. In the second, you use -t to specify the target directory first.

Finding Man Pages
#

apropos — Search by keyword
#

When you don’t know the command name, search the man page descriptions:

apropos partition
# cfdisk (8)           - display or manipulate a disk partition table
# fdisk (8)            - manipulate disk partition table
# parted (8)           - a partition manipulation program
# sfdisk (8)           - display or manipulate a disk partition table

apropos "copy file"
# cp (1)               - copy files and directories
# install (1)          - copy files and set attributes

apropos searches the NAME section of all man pages. It’s equivalent to man -k:

man -k network

whatis — One-line description
#

whatis grep
# grep (1)             - print lines that match patterns

whatis mount
# mount (2)            - mount filesystem
# mount (8)            - mount a filesystem

Updating the man page database
#

apropos and whatis rely on a database. If they return nothing, update it:

sudo mandb

Practical Examples
#

Find all man page sections for a command
#

man -f open
# open (1)             - start a file in its preferred application
# open (2)             - open and possibly create a file

# Then read the one you need
man 2 open

Search for all pages about “firewall”
#

apropos firewall
# firewalld (1)        - Dynamic Firewall Manager
# iptables (8)         - administration tool for IPv4 packet filtering
# nft (8)              - nftables command line tool

Read just a specific section of a man page
#

Use the search feature. Open the man page and jump directly to EXAMPLES:

man rsync
# Then type:
/^EXAMPLES

The ^ anchors to the start of a line, so this finds the EXAMPLES heading.

View a man page for a config file
#

man 5 sshd_config     # SSH server configuration options
man 5 resolv.conf     # DNS resolver configuration
man 5 fstab           # Filesystem mount table format
man 5 sudoers         # sudo configuration file

This is one of the most underused features. When you need to edit a config file and aren’t sure of the syntax, the section 5 man page has the authoritative reference.

man vs --help vs info
#

You’ll encounter three documentation systems:

MethodWhen to use
man commandFull documentation — options, examples, related files
command --helpQuick summary of flags — enough when you just need a reminder
info commandExtended documentation (GNU tools) — more verbose, hyperlinked

In practice, man is what you’ll use 90% of the time. --help is useful for a quick flag check without opening the pager. info has more detail for some GNU tools (like tar, coreutils) but most people never need it.

# Quick flag reminder
tar --help | grep "exclude"

# Full explanation with context
man tar

Controlling How Man Pages Display
#

Open in a specific pager
#

# Use less (default)
man ls

# Pipe to grep for quick searches
man ls | grep -A2 "\-t,"

Export a man page to plain text
#

man ls | col -bx > ls-manual.txt

View a man page from a specific path
#

man ./my-custom-tool.1

Section 2 and 3: For Developers
#

If you write C programs or want to understand how Linux works at a lower level, sections 2 and 3 are essential:

man 2 fork            # How processes are created
man 2 execve          # How programs are launched
man 2 open            # How files are opened at the kernel level
man 2 socket          # How network sockets are created

man 3 malloc          # Memory allocation
man 3 strcmp           # String comparison
man 3 getenv          # Reading environment variables

These pages document the interface between your programs and the Linux kernel (section 2) or the C standard library (section 3). Even if you don’t write C, reading these helps you understand what’s happening beneath the shell commands you run daily.

Best Practices
#

  • Start with man command before searching the web — it’s faster, works offline, and is always accurate for your installed version
  • Use man 5 filename when editing config files — the syntax reference is right there
  • Use apropos keyword when you know what you want to do but not which command does it
  • Check SEE ALSO at the bottom of man pages — it links to related tools and pages you might need
  • Use man -f command to discover if a command exists in multiple sections
  • Search within man pages with /pattern — don’t read top to bottom when you need one specific flag
  • Read the SYNOPSIS carefully — it tells you the exact invocation syntax without guessing
  • Run sudo mandb if apropos returns empty results — the database may need refreshing
linux-beginner - This article is part of a series.
Part 6: This Article