1. Overview

Sometimes, in the command-line interface, we want to see the documentation of a specific command.

In this quick tutorial, we’ll discuss how to get information for the commands in Linux using the man command.

2. man Page Organization and Structure

The man command is used to display the user manual of a command.

Usually**,** the argument given to man is the name of a program, a utility, or a function. Thus, the manual page related to each of these arguments is then found and displayed.

2.1. Numbered Sections

In general, the collection of manual pages for the system is divided into numbered sections. These section numbers and corresponding page types are:

  1. Executable programs or commands
  2. System calls (functions given by the kernel)
  3. Library calls (functions given by the library)
  4. Special files (usually found in /dev)
  5. File Formats and conventions (configuration files such as etc/passwd)
  6. Games (such as character-based applications)
  7. Miscellaneous (e.g. man (7))
  8. System administration commands (usually only for root)
  9. Kernel routines (non-standard)

2.2. Named Sections Within Each man Page

Within each manual page, there are many named sections. By default, these include NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUE, and ERRORS.

In addition, man pages can include sections named ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and SEE ALSO.

3. Syntax

Now, let’s take a look at the basic syntax of the man command:

$ man [option].. [command name]..

For example, to get information about the passwd command, we can use:

$ man passwd

PASSWD(1)                          User utilities                       PASSWD(1)

NAME
       passwd - update user's authentication tokens

SYNOPSIS
       passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username]

DESCRIPTION
       The passwd utility is used to update user's authentication token(s).

       This task is achieved through calls to the Linux-PAM and Libuser API.  Essentially, it initializes itself as a "passwd" 
service with Linux-PAM and utilizes configured password modules to authenticate and then update a user's password.

3.1. Search by Keyword in Manual Pages

We can get the results matching a keyword or regular expression in all the manual pages using the -k option.

Now, let’s see what we can find with the -k option:

$ man -k printf

asprintf (3) - print to allocated string
dprintf (3) - formatted output conversion
dprintf (3p) - print formatted output
fprintf (3) - formatted output conversion

Here, we see a list of all man pages returned that match printf as a regular expression.

3.2. Display All Sections for a Command Sequentially

In default mode, the man command only shows the most relevant man page. We can ask the man to display all the matching man pages sequentially by using the -a option. Let’s see how to use this option to list all the matching man pages:

$ man -a intro

--Man-- next: intro(2) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(3) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(4) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(5) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(6) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(7) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: intro(8) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

As a result, all the relevant man pages for the intro command are displayed in succession.

3.3. Display a Specific Numbered Section

As we know, the manual is divided into multiple sections. We can pass the section number as an argument to get to a specific manual section for a given command.

Let’s see an example — we’ll look up section 3 of the printf command:

$ man 3 printf
PRINTF(3)                                                  Library Functions Manual                                                 PRINTF(3)

NAME
     printf, fprintf, sprintf, snprintf, asprintf, dprintf, vprintf, vfprintf, vsprintf, vsnprintf, vasprintf, vdprintf – formatted output
     conversion

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <stdio.h>

     int
     printf(const char * restrict format, ...);

     int
     fprintf(FILE * restrict stream, const char * restrict format, ...);

...

Also, we can explicitly check section 1 in the same command:

$ man 1 printf
PRINTF(1)                                                  General Commands Manual                                                  PRINTF(1)

NAME
     printf – formatted output

SYNOPSIS
     printf format [arguments ...]

DESCRIPTION
     The printf utility formats and prints its arguments, after the first, under control of the format.  The format is a character string
     which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences which
     are converted and copied to the standard output, and format specifications, each of which causes printing of the next successive
     argument.
...

Also, we can check general information about the types of entries found in each section of the manual using the intro command. This can be a useful way for users to become more familiar with the different sections of the man pages. For example, to view the introductory information for section 2:

$ man 2 intro

INTRO(2)                                       Linux Programmer's Manual
              INTRO(2)

NAME
       intro - introduction to system calls

DESCRIPTION
       Section 2 of the manual describes the Linux system calls. A system call is an entry point into the Linux kernel. Usually, 
       system calls are not invoked directly:instead, most system calls have corresponding C library wrapper functions which 
       perform the steps required (e.g., trapping to kernel mode) in order to invoke the system call. 
       Thus, making a system call looks the same as invoking a normal library function.

3.4. Find the Filesystem Location of a Command’s Manual Page

Furthermore, we can locate a man page in the filesystem using the -w option:

$ man -w ping 

/usr/share/man/man8/ping.8.gz

As shown above, we can see the filesystem location of the man page for the ping command.

Finally, we can read about the man command using man itself:

$ man man

4. Conclusion

In this quick tutorial, we’ve seen how to use the man command.

First, we covered what the man command does, then we discussed manual sections, page types, and command syntax. After that, we touched upon several topics such as moving into specific sections, filtering by keyword, and finding the filesystem location of a manual.

Finally, we’ve explored how to use the man command effectively while working on Linux.