1. Overview

In this tutorial, we’ll learn about navigating manual pages. Mastering the man page is key to being comfortable and proficient with Linux.

The man page provides a lot of information. This makes it overwhelming to read the manual to find the needed information. Let’s see how to utilize man efficiently.

2. How to Get Help

What happens when we forget a shortcut key to operate within man or if we’re unsure of what options exist? Google shouldn’t be our default go-to when we want to know how to maneuver the manual in Linux. The man page already contains this information.

To get a quick summary of what options are available within the man page, we use the -h flag:

$ man -h
Usage: man [OPTION...] [SECTION] PAGE...
  -C, --config-file=FILE     use this user configuration file
  -d, --debug                emit debugging messages
  -D, --default              reset all options to their default values
      --warnings[=WARNINGS]  enable warnings from groff
**more options

The -h flag gives us a brief description of how to use each flag.

Additionally, if we want to get more information, we can open the man page for man itself:

MAN(1)                        Manual pager utils                        MAN(1)
NAME
       man - an interface to the system reference manuals
SYNOPSIS
       man [man options] [[section] page ...] ...
**more details

The result shown gives us a better understanding of the man page, and we get further details on the options available.

3. Understanding the Sections of the man Page

As we mentioned, the man page is structured to give different results. Most of the time, we focus on how to use a particular command and its options. Often, we fail to explore all the information available in the manual. Let’s discuss how to view other materials beyond usage information.

3.1. Sections of the man Page as Subdivisions

There are different blocks of information categories in a man page. For instance, let’s run:

$ man ls
LS(1)                            User Commands                           LS(1)
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...
DESCRIPTION

From the output, it’s evident that the information we get is separated into blocks. Each of these blocks has a heading. Some of the titles we see are NAME, SYNOPSIS, DESCRIPTION, etc. We can refer to these blocks as sections. For instance, if we tell a user to look at the SYNOPSIS section of the man page for passwd, then we expect the user to focus on this section of the output:

$ man passwd | grep -A 2 'SYNOPSIS'
SYNOPSIS
       passwd [options] [LOGIN]

3.2. Sections of the man Page as Chapters

The manual is very extensive, and each command is well-explained. For example, one chapter covers how to use a command, while the other touches upon any supplementary relevant information. The manual has a total of nine sections.

Often, we concentrate on the usage information when we look at the manual. As a result, it’s easy to overlook the other details on the man page. If we want to examine parts of the manual apart from the usage information, we use the whatis command to view these other sections.

We’ll get a one-line summary of the man page:

$ whatis passwd
passwd (1)           - change user password
passwd (1ssl)        - OpenSSL application commands
passwd (5)           - the password file

We can also find references to other manual sections of a single command by scrolling to the SEE ALSO section of the man page (Shift + g takes us to the end of the file where this is located):

$ man passwd | tail -4 
SEE ALSO
       chpasswd(8), passwd(5), shadow(5), usermod(8).

We can tell from which section the information was fetched by looking at the number appended to the name on the right, inside the parentheses.

3.3. Viewing Specific Sections of the man Page

To open the usage information of a command, we run:

$ man passwd
PASSWD(1)                        User Commands                       PASSWD(1)
NAME
       passwd - change user password
SYNOPSIS
       passwd [options] [LOGIN]

Apart from the usage information, we can open other sections (the chapters) of the manual for passwd by specifying the section number:

$ man 5 passwd
PASSWD(5)               File Formats and Configuration               PASSWD(5)
NAME
       passwd - the password file
DESCRIPTION
       /etc/passwd contains one line for each user account, with seven fields
       delimited by colons (“:”). These fields are:

We can also write it this way:

$ man passwd.5

4. Navigating With Shortcut Keys

Let’s discuss how to navigate the man page faster. Usually, we use the Up and Down arrows to scroll the man page. There are various shortcut keys we can use to move the contents of the man page more quickly:

Key Function
j pressing j takes us forward. If we add a number before j, we move forward by that number of lines, e.g., 6j takes us six more lines ahead.
k pressing k to move us back one line. Similarly, if we enter a number with k, it takes us back to that number of lines.
g if we want to scroll to the top, we press g
G pressing g with the tab on takes us to the end of the manual
f the f key takes us one screen ahead. Alternatively, we can hit the space bar instead.
b to reverse and go back one window behind, we press b
d this key takes us one-half of a window forward. And the remaining half is set to next.
u the u key takes us one-half of a window behind
q if we’re done with the manual, we press q to exit

5. Searching by Section

While we are using man pages, we can search in the following ways: searching by section, searching by keyword, and searching using patterns. Let’s discuss each of these.

5.1. Searching by Section

The manual has several sections. These sections are Shell commands and applications (1), Basic kernel services (2), Library information (3), Network services (4), Standard file formats (5), Games (6), Miscellaneous files and documents (7), System administration and maintenance commands (8) and Obscure kernel specs and interfaces (9).

If we want to look for information from a specific section in the manual, we use this syntax:

$ man -s section-number command

5.2. Searching by Keyword

If we’re unsure of the name of a command, we can use a search string to look for a keyword that matches the manual. Using the -k flag with man makes it equivalent to the apropos command:

$ man -k passwd   
chgpasswd (8)        - update group passwords in batch mode
chpasswd (8)         - update passwords in batch mode
expect_mkpasswd (1)  - generate new password, optionally apply it to a user
gpasswd (1)          - administer /etc/group and /etc/gshadow
grub-mkpasswd-pbkdf2 (1) - generate hashed password for GRUB

Let’s strictly limit the results from the matched string by adding a caret (^):

$ man -k '^passwd'
passwd (1)           - change user password
passwd (1ssl)        - OpenSSL application commands
passwd (5)           - the password file

We can also use the man command with the -f flag. This flag is equivalent to the whatis command.

5.3. Searching Using a Pattern

The manual allows us to search either forward or backward from our current position. We use the / to search forward. Contrarily, we use the ? to search in the reverse direction.
Let’s press / and then type the string we’re looking for, and hit Enter:
forward slash search
We use n to move forward and N to move backward. Next, we press the ? to bring up the prompt and type the string we want to find:
question mark
It’s imperative to note that both the / and the ? should be followed with a subsequent string. Otherwise, they both return the last pattern searched.

Furthermore, we can also modify our search only to return numbered lines. To enable this, we press -N followed by the return key while on the man page:

numbered
It numbers all the lines:
numbered
When we click on the ampersand (&) and then type our search term, we only get a list of lines with the matched string:
ampersandone
To return to the output results, we press the & key.

6. Running a Command Within the man

The man page allows us to run commands inside it without switching consoles. For example, if we want to test ls, we type !ls:
test command
Afterward, we press Enter and get the output displayed. We hit Enter again to return to the man page.

7. Conclusion

In this article, we’ve examined how to navigate the man pages efficiently.

Firstly, we discussed how to get help, followed by understanding the different sections of the man page. Then, we discussed the shortcut key we can use inside the manual. Next, we looked at how to search for strings inside the man page. Finally, we looked at how we can run a command within the manual.

All these make us use the man page more efficiently, saving us a lot of time as we can quickly get the information we need.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.