keepcalculator

06 Numbers and Powers

Search Man Pages: Command Line How-To

Card No. 06·64773 · Updated · Standard formula, shown below

The man command is the standard way to read manual pages (man pages) directly from the command line on Linux and Unix-like systems. You enter man [options] topic and get a formatted, searchable document for that command, file format, or system call. This article explains how to search man pages effectively, including keyword searches, section-specific lookups, and common pitfalls.

What Are Man Pages?

Man pages are the built-in documentation for Unix-like operating systems. They originated with AT&T Unix in the 1970s and remain the primary reference for commands, system calls, library functions, device drivers, file formats, and even games. Each page is written in a markup language called troff (or groff on GNU systems) and rendered by the man utility into a readable format, usually with a pager like less.

Man pages are organized into numbered sections. The most common are:

  • 1 – User commands (e.g., ls, cp)
  • 2 – System calls (e.g., fork(), open())
  • 3 – Library functions (e.g., printf(), malloc())
  • 5 – File formats and conventions (e.g., /etc/passwd)
  • 8 – System administration commands (e.g., mount, useradd)

When you type man ls, the system searches these sections in order and displays the first match. If a command exists in multiple sections, you may need to specify the section number explicitly.

How to Search Man Pages by Name

The simplest search is by exact command name. For example, man grep shows the manual for grep. But what if you don’t know the exact name? The man -f option (equivalent to whatis) gives a one-line description of a command. For instance:

$ man -f printf
printf (1)           - format and print data
printf (3)           - formatted output conversion

This shows that printf exists in both section 1 (user command) and section 3 (library function). To read the library version, use man 3 printf.

If you only remember part of a name, use man -k (equivalent to apropos) to search the short descriptions and manual page names for a keyword. For example:

$ man -k copy
cp (1)               - copy files and directories
cpio (1)             - copy files to and from archives
scp (1)              - OpenSSH secure file copy

The -k option is a regex search, so you can use patterns like man -k '^copy' to match names starting with “copy”.

Searching Within a Man Page

Once you open a man page, you often need to find a specific option or phrase. The default pager is usually less, which has its own search commands:

  • Press / to search forward, then type your pattern and press Enter.
  • Press n to jump to the next match, N for the previous.
  • Press ? to search backward.
  • Use -i to toggle case-insensitive search (or start less with -i).

For example, to find the -r option in man cp, type /-r and press Enter. The search is a regular expression, so a hyphen is literal, but a dot matches any character. To search for a literal dot, escape it with a backslash: \.

If your system uses a different pager (like more), the commands differ: more uses / for search but only n for next, and no backward search.

Finding the Right Section

Many commands have pages in multiple sections. For example, man printf shows the shell built-in version (section 1) by default, but the C library function is in section 3. To see all sections, use man -a printf which displays all matching pages sequentially. Or use man -w printf to print the file paths of all matches:

$ man -w printf
/usr/share/man/man1/printf.1.gz
/usr/share/man/man3/printf.3.gz

If you know the section, specify it as the first argument: man 3 printf. This is essential for system calls and library functions, which often share names with user commands (e.g., stat, kill, chmod).

To list all sections available on your system, check the MANPATH environment variable or look in /usr/share/man. The default search order is defined in /etc/man_db.conf (on Debian-based systems) or /etc/man.conf (on others).

Advanced Search Techniques

Beyond man -k, you can use the apropos command with regex for more precise searches. For example, apropos '^zip' finds all commands starting with “zip”. The man -K option (capital K) searches the full text of all man pages for a string. This is slow but powerful:

$ man -K "environment variable"

This searches every man page on the system for that phrase. On large systems it can take minutes, but it’s invaluable when you don’t know which command handles a concept.

Another trick: use man -H to output HTML, which you can open in a browser. Some systems also provide man2html for converting pages to HTML.

Common Problems and Solutions

  • “No manual entry for X” – The command may not be installed, or its man page is missing. Try apt-get install manpages (Debian/Ubuntu) or yum install man-pages (RHEL/CentOS). Some commands are shell built-ins (e.g., cd, alias) – use help cd instead.
  • Man page not found for a third-party tool – Ensure the tool’s man directory is in your MANPATH. For example, if you installed something in /usr/local, add export MANPATH=/usr/local/man:$MANPATH to your shell profile.
  • Poorly formatted output – If the man page looks like raw text, your PAGER may not handle bold/underline. Set export PAGER=less and ensure less is installed.
  • Searching inside a compressed man page – Man pages are often gzipped (.gz). The man command handles this automatically, but if you try to grep them directly, use zgrep instead.

Alternatives to Man Pages

While man pages are the classic reference, other documentation systems exist:

  • Info pages – GNU’s hypertext documentation system. Run info coreutils for detailed guides. Often more structured than man pages, but less common.
  • Help commands – Many commands have --help or -h flags that give a quick summary. For example, ls --help.
  • Online resources – Websites like man7.org, die.net, and linux.die.net host man pages with search. Useful when you’re not on a Unix machine.
  • Shell built-in help – For bash built-ins, type help to list them, or help for details.

Each has its place: --help for a quick reminder, man pages for full reference, info for tutorials, and online for cross-referencing.

Frequently Asked Questions

Why does man printf show a different page than man 3 printf?

Because there are two different printf entries: one for the shell command (section 1) and one for the C library function (section 3). The default section order puts section 1 first, so man printf shows the shell version. Specify the section number to get the other.

How do I search for a man page when I only know what it does?

Use man -k keyword or apropos keyword. This searches the NAME section of all man pages. For example, man -k "copy files" returns cp and install.

Can I search man pages on the internet from the command line?

Yes, but not with the built-in man command. You can use curl to fetch pages from sites like man7.org, or use tools like man-online (not standard). Most users just install the man pages locally.

Why does my man page output look garbled?

This usually happens when the pager doesn’t interpret the formatting codes. Set PAGER=less and make sure less is installed. Also, check that the groff package is installed, as it renders the man page source.

How do I print a man page to PDF?

Use man -t command | ps2pdf - output.pdf on systems with PostScript support. Alternatively, man -H command outputs HTML, which you can print from a browser.

Is there a way to read man pages in a GUI?

Yes, many desktop environments have a Help viewer (e.g., GNOME’s yelp) that can display man pages. You can also use man -H to generate HTML and open it in any browser.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →