man Command in Linux: Read, Search and Save Manual Pages

LinuxForDevices featured banner: Read Manuals Without Guessing

man opens the manual page for a command from /usr/share/man, right there in the terminal. No network, and no browser tab.

man -k found the page I could not name from its one-line description, and man -f listed two pages under the same name. The section number settles which one you get.

What man reads, and what a section is

A manual page is not a text file sitting on disk. The file is compressed roff source, and man formats it with groff the moment you ask, then hands the result to a pager.

man -w prints the file that would be shown instead of showing it. For the ls command that is /usr/share/man/man1/ls.1.gz, whose header line reads .TH LS "1" "August 2026" "GNU coreutils 9.4", which is why two machines with different coreutils print two slightly different pages for the same name.

The number in parentheses after a page name is its section, and one word can exist in several of them. Each number answers a different question about the same name, so the section you leave out decides what you get.

SectionWhat it holdsA page in it
1Executable programs and shell commandsman(1), ls(1)
2System calls provided by the kernelopen(2)
3Library calls inside program librariesprintf(3), crypt(3)
4Special files, usually device nodesnull(4)
5File formats and conventionspasswd(5), crypt(5)
6Gamesintro(6)
7Miscellaneous, including macro packagesman(7), groff(7)
8System administration commands, usually run as rootchpasswd(8)
9Kernel routines, non standardnone installed by default

man shows the first page it finds and stops, even when the name matches more than one section. The order comes from the man-db configuration and starts 1 n l 8 3 0 2 3type 5 4 9 6 7, so man printf lands on the shell command in section 1 rather than the C function in section 3.

I checked both pages under that name, and they share nothing beyond the word printf in their NAME lines.

nginx(8) manual page opened with the man command
The nginx page: the 8 in parentheses marks an administration page, NAME carries the one-line description, and SYNOPSIS gives the argument order the rest of the page assumes

Every page keeps that shape. The NAME line is the sentence man -k searches, the SYNOPSIS is the argument order the examples assume, and OPTIONS is where the flag you came for is listed.

The option set in this piece is the one the man-db project publishes on its man(1) page, which is the same text the local man prints.

What has to be on the system

A manual page is not always installed with the command it documents, and a small server build can carry ls without carrying the ls page. Which piece is missing decides which command fixes it.

What has to be thereWhat breaks without itHow to check
man-dbman, apropos, whatis and mandb do not exist at allcommand -v man
The page for that packagethe command runs and man reports no entry for itman -w ls
The index fileskeyword search answers nothing appropriatels -l /var/cache/man/index.db
A pager such as lessthe page prints once with no scrolling and no searchecho $PAGER
The groff package, not only groff-base-Tpdf stops before it formats anythingcommand -v gropdf
A terminal width, or MANWIDTHlong lines wrap at whatever the window gives themecho $MANWIDTH

On a minimal Ubuntu image the missing pieces arrive together.

sudo apt install man-db

The first check I run is command -v man, because the rest of the table follows from it. The system call and library pages come from manpages and manpages-dev, so a section 2 or 3 lookup that returns nothing for a function the kernel implements means those two packages are absent.

Find the page you need

The commands that matter here split by what you already know. If you have the name, one opens the page, and if you only have the topic, another searches the descriptions.

A third command settles the case where one name points at several pages.

Open a page by name

man followed by the page name opens the pager at the top of the page. The -w flag stops before the pager and prints the file instead, which is the fastest way to find out whether a page exists.

man -w ls

That path tells you which section won and which package owns the page. It is the same route whereis takes when it prints a binary beside its page.

The -l flag reads a file you already have instead of looking a name up, which is how a page pulled from another machine gets rendered with the local formatter.

Search the descriptions with man -k

A keyword search reads the one-line descriptions rather than the names, so it reaches a page whose name you would never guess.

man -k crypt

Each line that comes back is a page mentioning the word in its description, with the section in parentheses. apropos is the same command under another name, so the flag and the standalone tool share one index.

man -k crypt listing manual pages that mention crypt
A keyword search returns the pages that mention the word, and the section in parentheses is what you pass to man next

Section filtering narrows the same search when you already know the kind of page you want. Apart from a shorter list, it keeps the library calls out of a search for a command.

man -k --sections=1 crypt

Each hit carries the section number that turns the name into an addressable page, so the list is usable as it stands.

I found the library call, the file format and the kernel documentation for crypt from that one word.

Decide between two pages with the same name

man -f prints every page whose name matches, one line each. Reach for it when a page describes something other than the command you type.

man -f printf; man -w -s 3 printf

The first line of that output is printf(1), the shell command, and the second is printf(3), the C function. Naming the section picks the file, which the second command proves by printing /usr/share/man/man3/printf.3.gz.

man -f printf listing sections 1 and 3 for the same name
Both pages exist under one name, and the section number in the second command prints the file the section 3 page comes from

Show every page with that name

The -a flag walks the whole match list instead of stopping at the first page, and whatis answers the same question as man -f.

man -a open

That name opens two pages in sequence, the desktop launcher in section 1 and the system call in section 2. Press q to leave the first one and the second follows.

Read it without drowning in it

The pager owns everything between the page opening and the answer you came for, and on a stock install it is less. A short key list covers the whole job, and I reach for three of those keys.

KeyWhat it does
/textsearches forward from the current line, and n jumps to the next match
g and Gjump to the top and the bottom of the page
Space and bmove one screen forward and one screen back
qleaves the pager, and this is the key to remember
hthe pager key list, which man does not repeat

The search is the one to learn first, because it works on every page you open, however long the page runs.

MANPAGER picks that program, and PAGER is the fallback when MANPAGER is unset. Setting the variable to cat makes the page print straight through, which is what the pipeline examples below do one command at a time.

Search a page from the shell

When the page has to be filtered rather than read, cat takes the pager out of the pipeline and grep does the matching.

man --pager=cat ls | grep -n -e '--sort'

Every line that mentions the flag comes back with a line number, so the option can be read where it sits. Reaching for the pipeline is worth it when the result feeds something else, and the search inside the pager is faster when you only want to read it.

A narrow terminal wraps the page at its own width. MANWIDTH overrides that width without resizing anything.

MANWIDTH=60 man ls

The same page then wraps near 60 columns, which keeps the option list readable in a split window or a side pane.

Keep a page as text

man --pager=cat ls > ls-manual.txt

The ls page writes out at 249 lines and 8,383 bytes, which I measured with wc after the redirect.

Man pages draw bold with backspaces rather than escape sequences, so a page captured through the pager carries control characters. The col filter removes them.

man ls | col -b > ls-manual.txt
man ls redirected to a file and read back with cat
The redirect writes the page to a file, and reading it back with cat or less confirms the whole page arrived

Reading the export back is the check that matters, since a redirect that fails partway leaves a truncated file and a silent shell.

Keep a page as PDF

man -Tpdf looks like the flag for this job. I ran it expecting a PDF and got a groff error instead, before a single line was formatted.

man -Tpdf ls
man -Tpdf ls failing with a missing groff device description
The failure names the missing piece: the pdf device is absent, so groff cannot load its description file

The message points at the device rather than the page. That device ships in the groff package, while groff-base, the package a server image carries, leaves it out.

sudo apt install groff

Without that package the route that works is PostScript through ps2pdf, which arrives with Ghostscript.

man -t ls | ps2pdf - ls.pdf; file ls.pdf
PostScript from man converted to a PDF and confirmed with file
The ls page becomes a 4-page PDF of about 32 KB, and the file command confirms the format rather than the exit code

When man gives you nothing

man exits with status 16 when a page, a file or a keyword did not match, and the message on the terminal says which of the three it was.

What you seeWhat it meansWhat to run
zzzz: nothing appropriate.the keyword index is missing, stale or unreadablesudo mandb
No manual entry for cdno page is installed under that name, and cd is a shell builtinhelp cd
man: can’t resolve man7/groff_man.7a SEE ALSO cross reference points at a page that is not installedman groff
man: command not foundman-db is missing, which is normal in container imagessudo apt install man-db
cannot load ‘DESC’ description file for device ‘pdf’groff-base is present without the pdf devicesudo apt install groff
No manual entry for a command that existsthe page sits in a hierarchy that MANPATH does not listmanpath

The codes either side of 16 carry their own meaning. A clean read returns 0, a usage or configuration problem returns 1, an operational failure returns 2, and status 3 means a child process in the pipeline failed, which is the code the missing pdf device produces.

The builtin case is the one worth naming, because no package can supply a page for it. cd, alias and history live inside the shell, and help prints their documentation while man cannot.

The keyword index is the other case worth recognising, because man -k and apropos read a cache built by mandb. A container image or a freshly installed package tree can leave that cache empty until someone rebuilds it.

I reproduced that miss with a nonsense word, and the reply is nothing appropriate plus exit status 16.

sudo mandb

The rebuilt cache answers the next keyword search, and the rebuild itself runs through sudo because the cache directory belongs to the man user.

The page for man documents the parts you just used

The page you have been reading belongs to the tool itself. man(1) carries MANSECT for the section order, MANWIDTH for the wrap, and an EXIT STATUS section that gives 16 as the code for a page, file or keyword that did not match.

The search is what I kept, because a task word stands in for a name. The description it matches is the sentence you would have written yourself.

man -k password

That returns chage(1), chpasswd(8) and the rest of the password tools, which is a shorter list than a web search and one keystroke away from the page I want, which is the habit the Linux commands cheat sheet extends to the rest of the commands you reach for.

Frequently asked questions

How do you exit a man page?

Press q. The pager waits for that key, and it also answers h with its own key list.

How do you search inside a man page?

Type / then the word you want and press Enter. n jumps to the next match and N to the previous one.

How do you read a man page from a specific section?

Put the section number before the name, as in man 3 printf. man -f printf lists the sections that exist for that name.

What does nothing appropriate mean?

The keyword index that man -k and apropos read is missing or stale. Run sudo mandb and repeat the search.

How do you install man when the command is not found?

Run sudo apt install man-db. Container images and small server builds ship without it.

How do you save a man page to a file?

man –pager=cat ls > ls.txt writes plain text, and man -t ls | ps2pdf – ls.pdf writes a PDF.