logo

Linux - man

The man command (short for manual) is the standard built-in documentation system for Linux and Unix-like operating systems. It provides detailed reference pages for commands, system calls, library functions, and configuration files.

The Command Syntax

The basic way to use it is:

man [command]

Example: man ls will show you the manual for the "list directory contents" command.

The 8 Standard Sections

The manual is divided into numbered sections. This is important because some names exist in multiple places. For example, printf is both a shell command and a C library function.

Section Content Type Examples
1 Executable programs or shell commands ls, grep, top, bash
2 System calls (functions provided by the kernel) open, fork, read, execve
3 Library calls (functions within program libraries) printf, malloc, scanf
4 Special files (usually found in /dev) null, zero, tty, random
5 File formats and conventions /etc/passwd, /etc/shadow, fstab
6 Games fortune, sol (classic, often empty today)
7 Miscellaneous (standards, macros, protocols) man, regex, utf8, ip
8 System administration commands (root only) fdisk, reboot, iptables, visudo

How to specify a section:

If you want the C library version of printf (Section 3) instead of the bash command (Section 1), you type:

man 3 printf

Anatomy of a Man Page

Most man pages follow a standardized layout so you can find information quickly:

  • NAME: The name of the command and a one-line summary of what it does.
  • SYNOPSIS: The "blueprint" of how to run the command (the syntax).
    • Bold text: Type exactly as shown.
    • Italic/Underlined: Replace with your own argument.
    • Square brackets []: Optional arguments.
  • DESCRIPTION: A detailed explanation of what the tool does.
  • OPTIONS: A list of every flag (like -l or --help) and what it does.
  • EXIT STATUS: What numerical code the program returns when it finishes (0 usually means success).
  • EXAMPLES: (The most helpful part, though not always present).
  • SEE ALSO: Related commands or files.

Navigation (The "Less" Pager)

When you open a man page, it usually opens in a program called less. You navigate it using your keyboard:

  • Arrow Keys / J, K: Scroll up or down by one line.
  • Spacebar: Scroll down by one page.
  • b: Scroll back up by one page.
  • /[keyword]: Search for a word. (Example: /recursive searches for that word).
  • n: Find the next occurrence of your search.
  • N: Find the previous occurrence.
  • q: Quit the manual and return to the terminal.

Useful Searching Shortcuts

"What is this command?" (whatis)

If you just want the one-line summary without opening the whole manual:

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

"I don't know the command name" (apropos)

If you want to find a command that does something specific, search the descriptions:

apropos "search text"
# or
man -k "search text"

"Where are all the man pages for this?"

To see every section that contains a specific word:

man -aw printf
# Output:
# /usr/share/man/man1/printf.1.gz
# /usr/share/man/man3/printf.3.gz

Fun Fact: The "Manual of the Manual"

If you want to read the manual for the man command itself, just type:

man man

This will explain every technical detail about how the manual system is organized, where the files are stored (/usr/share/man), and how to format your own man pages using the troff typesetting system.

The junk drawer

Much like ioctl is the "junk drawer" for system calls that don't fit into standard categories like read or write, Section 4 (and sometimes Section 5) serves as the "everything else" space for system definitions.