How to Use the man command in Linux

When you install a software package, it automatically installs its manual pages that explain the package's functionality and provides a detailed description of how to use it. For example, if a package installs a command, its manual pages explain how to use it, or if it provides a service, they describe what configuration files it requires and how to configure them.

Manual pages are authoritative resources for information about a command's functions and options, configuration file directives, installation paths, etc. They also include how-to-use examples. In short, they contain all the information you need to use the commands or services the package offers.

A manual may have hundreds of pages written in plain text format. Furthermore, it keeps them in archive format. To obtain information from a manual directly, you must extract it and read all pages stored in plain text format. It is a challenging task. The man command makes it easy. It extracts the archive in fly, formats the text, and displays it on the prompt. It also offers many options to navigate, search, and control the output. A manual page usually consists of the following sections: name, synopsis, configuration, description, options, exit status, return value, errors, environment, files, versions, conforming to, notes, bugs, example, authors, and see also.

Sections on manual pages

The man command groups similar types of manual pages and assigns a unique value to each group. These groups are known as sections. Sections allow us to limit the results. By specifying the section number, you can instruct the man command to find the specified keyword only in particular types of manual pages. For example, suppose you are looking for a command or a configuration file. In that case, you can instruct the man command to search it only in man pages that provide information about that particular command or configuration file.

The following table lists the sections of manual pages.

Section Description
1 Shell commands or executable programs
2 Kernel error codes or system calls
3 Library calls
4 Hardware files and device drivers
5 System configuration files
6 Files related to games and demonstrations
7 Miscellaneous files and documents
8 System administration commands
9 Kernel specification and interfaces

The term section has two meanings in the context of manual pages. These are sections of a manual page and sections of manual pages.
Sections of a manual page refer to the information available on a single manual page.
Sections of manual pages refer to a scheme the man command uses to categorize all available manual pages on the system.

the sections of man page and manual pages

The man command syntax and options

The man command uses the following syntax.

$man [option] [section] keyword

The following table lists essential options of the man command.

Option Description
-f Display a short description.
-k Search the specified keyword in the short descriptions section of manual pages
-K Search the specified keyword in all sections of all manual pages
-l Format and display local manual files instead of searching through the system's manual collection
-w Instead of displaying the manual page, display the location of the manual page

Using the man command

By default, the man command searches the specified keyword only in the title of man pages. If you know the name of the command or configuration file, you can search its manual page by specifying its name as an argument to the man command. For example, the following command searches and displays the man page of the chgrp command.

the man command example search a command's man page

The following command searches and displays the man page of the yum.conf configuration file.

the man command example search a configuration file's man page

Without any options, the man command searches the specified keyword in the title of manual pages of all sections in ascending order until it finds a match. If it finds a match, it stops searching and displays the manual page whose title matches the specified keyword.

Since it searches sections in ascending order, it shows the first match. Let us take an example. Linux has a command and configuration file named passwd. The passwd command allows you to manage user passwords from the command line. The passwd configuration file saves local users' passwords and other related information. Both install separate man pages. The system assigns section 1 to the manual pages of the passwd command. It assigns section 5 to the manual pages of the passwd configuration file. If you use the man command to search for the keyword passwd without an option, it always returns the passwd command's man page (1 < 5).

the man command default search

You can override the default behaviour by specifying the section number. If the section number is selected, the man command searches the specified keyword only in the restricted section. For example, to view the man page of the passwd configuration file, use the following command.

#man 5 passwd

Since we have specified the section number in the above command, the man command will only search for the keyword passwd in the title of the man pages arranged in section 5.

the man command section search

Searching in the short description section

If you don't know the name of the command or configuration file, you can search for a keyword that describes your requirement in the short description section of manual pages. For example, suppose you want to create a new user account but do not know which command adds a new user. In this case, you can search for the keyword 'user' in the short description section of manual pages. To search the string in the short description section of manual pages, use the option -k. The following command prints the title and short description of all manual pages with the keyword 'user' in their short description section.

searching a keyword in manual pages

Depending on the uniqueness of the specified keyword, you may get many results. If that happens, you can search for a text string instead of a keyword. To find a text string, put the string in quotes. For example, you can search a text string 'create a new user' instead of the keyword 'user'.

#man -k 'create a new user'

searching a string in manual pages

Caching of manual pages

The man command uses a database to save information about manual pages, such as where a manual page is available on the file system and what it contains. When we use this command to get information about a command or a package, instead of finding the related manual pages on the file system, it uses the database to know the exact location of manual pages related to the specified command or package.

It also maintains a cache of formatted pages in the /var/cache/man and /usr/share/man directories. When you search a man page, the man command searches the specified man page in the cache directory instead of performing a full search. If a cached version of the requested man page is available, the man command immediately displays the cached version of the requested man page. If the cached version of the requested man page is not available, the man command performs a full search for the requested man page at the available locations in the index database.

Since it uses the database to locate the manual pages, it cannot find the manual pages of a recently added package until the following database updates. By default, Linux automatically updates the index database at the time specified in the cron file. But if required, such as in the exam, you can update this database manually. To update the index database manually, use the following command.

#mandb

updating database

This tutorial is part of the tutorial series 'Getting help on the command prompt on Linux'. Other parts of this series are the following.

Chapter 01  How to Use the help Command in Linux
Chapter 02  How to Use the man command in Linux
Chapter 03  How to use the info and pinfo commands in Linux

Conclusion

The man command displays the manual pages of the specified package or command. It provides a detailed overview of the package's features and functionality. Understanding how to navigate and utilize the manual command can enhance your ability to find the required information quickly.

ComputerNetworkingNotes Linux Tutorials How to Use the man command in Linux

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com