This article explains the basic usage of the man
command.
Introduction
The man
command displays manuals.
By mastering the man
command, you can look up command information on your own, even if you're not very familiar with the command.
Of course, searching on Google will yield many articles explaining how to use commands, but the manuals created by the original developers are the most accurate.
In this post, we'll go over how to use the man
command.
Note: This article was translated from my original post.
Understanding the Basics of the man
Command
Basic Usage of man
The simplest usage is man [command name]
.
For example, let's try displaying the manual for the man
command itself.
$ man man
MAN(1) Manual pager utils MAN(1) NAME man - an interface to the on-line reference manuals SYNOPSIS man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m system[,...]] [-M path] [-S list] [-e extension] [-i|-I] [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page[.sec‐ tion] ...] ... man -k [apropos options] regexp ... man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ... man -f [whatis options] page ... man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ... man -w|-W [-C file] [-d] [-D] page ... man -c [-C file] [-d] [-D] page ... man [-?V] ~
Press "q" to exit the manual.
You can use the same format to display manuals for other commands.
$ man ls
LS(1) User Commands LS(1) NAME ls - list directory contents ~
One thing to note here is the concept of "sections".
If you look closely at the result of man ls
, you'll see LS(1)
at the top.
The (1)
indicates that the ls
manual is in section 1.
Specifying a Manual Section
You can specify the manual section with man [section number] [command name]
.
Manual sections are categorized with numbers from 1 to 9.
You can check the section details in the man
manual, so if you forget, just run man man
.
1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program libraries) 4 Special files (usually found in /dev) 5 File formats and conventions eg /etc/passwd 6 Games 7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) 8 System administration commands (usually only for root) 9 Kernel routines [Non standard]
Note that not all manuals have entries in all sections from 1 to 9.
Searching Manuals
Next, let's look at the -k
option for searching manuals.
-k, --apropos Equivalent to apropos. Search the short manual page descriptions for keywords and display any matches.
By passing a string to the -k
option, it searches the descriptions of all manual pages and lists any matches.
Example:
$ man -k printf asprintf (3) - print to allocated string dprintf (3) - formatted output conversion fprintf (3) - formatted output conversion fwprintf (3) - formatted wide-character output conversion printf (1) - format and print data printf (3) - formatted output conversion snprintf (3) - formatted output conversion sprintf (3) - formatted output conversion swprintf (3) - formatted wide-character output conversion vasprintf (3) - print to allocated string vdprintf (3) - formatted output conversion vfprintf (3) - formatted output conversion vfwprintf (3) - formatted wide-character output conversion vprintf (3) - formatted output conversion vsnprintf (3) - formatted output conversion vsprintf (3) - formatted output conversion vswprintf (3) - formatted wide-character output conversion vwprintf (3) - formatted wide-character output conversion wprintf (3) - formatted wide-character output conversion
This is useful when you want to find related man
pages.
Searching Within a man
Page
Sometimes you may want to search for a string within an opening man
page rather than searching for the manual itself.
To search within a man
page while viewing the page, type:
Slash /
+ string
and press Enter to start the search.
Press n to go to the next match, or Shift + n to go to the previous one.
Conclusion
That's a quick overview of how to use the man
command.
By getting comfortable with the man
command, you can build the habit of checking the official manuals and documentation whenever you run into trouble.
[Related Articles]