Logo

How to Use man Command in Linux

Try this guide with our instant dedicated server for as low as 40 Euros

man command in linux

The wide range of commands and utilities in the Linux ecosystem is one of the most critical reasons behind the success of the operating system. You can find a command or utility to accomplish any task or objective you can think of. 

You can use the built-in man command in almost all Linux distributions to view essential information and usage options for the commands and utilities. This command accesses the user-friendly manual pages that you can read to understand how to use the command and its various flags and options.

In this tutorial, we will discuss the syntax and usage of the man command in Linux. We will also go into the details of several command options that help you better use the command to get help from the manual that comes with your Linux distribution.

Table Of Contents

  1. An Overview of the man Command in Linux
    1. The Syntax of the man Command
    2. The Idea of Sections in Manual Pages
    3. Common man Command Options
    4. The Prerequisites to Using the man Command
  2. Structure of a Linux man Page
  3. Navigate the Output of the man Command
  4. How to Use the man Command to Get Information About Linux Commands
    1. Scenario #1: Use man to Get Information About a Command
    2. Scenario #2: Get a Short Command Description
    3. Scenario #3: Get a List of All Pages About a Command
    4. Scenario #4: Display all Related man Pages
    5. Scenario #5: Get Information From a Specific Section
    6. Scenario #6: Display the Location of the Manual Pages
    7. Scenario #7: Use a Regex to Search for a Command
    8. Scenario #8: Run Case-sensitive Searches
  5. Conclusion
  6. FAQs

An Overview of the man Command in Linux

The earlier versions of Unix came with a printed and bound manual that you used to look up command options and usage. 

In recent years, the diversity in Linux distributions means that quick and easy access to documentation is a critical distinguishing point between the distributions.

The man command was introduced to bring the documentation to all users, regardless of their expertise. This command shows a comprehensive overview of the command, including how the command works in the Linux system’s command line.

The Syntax of the man Command

The traditional syntax of man in Linux environment is as follows:

# man [option] [section] [command]

In this syntax:

[option] is a list of flags that alter the default command’s behavior

[section] is an optional argument that indicates that the man command should refer to a specific section of the manual pages

[command] is your intended command.

The Idea of Sections in Manual Pages

Linux manual pages are extensive and well-organized into sections that group similar commands for easy reference. Each section is denoted by a number that you can use as an optional argument in the man command syntax. 

The following table presents the most common sections of the Linux manual pages:

Linux Manual Pages Sections
Section  Description
1 General terminal commands 
2 System calls & kernel functions
3

Library functions. Also includes the functions from the C standard library

4 Special files and drivers (covers system devices, especially those listed in /dev) 
5

Standard file formats and usage conventions

6 Games and screensavers
7 Misc commands and information on packages
8 Standard system administration commands and service daemons.

In addition, some distributions have additional sections (such as 9 for Kernel Information and Routines).

Common man Command Options

Like most Linux commands, you can modify the default behavior of the man command with flags. Here are the most common flags for the command:

Common Linux man Command Options
Option Description
-a Lists all matching entries.
-c Uses the cat command to list the manual information.
-f Displays information only about the command given as the final parameter.
-F Lists the first matching entry.
-k Displays each line in the database that contains the final parameter.
-m Only search in the paths specified in MANPATH or with the -M option.
-M [path] Changes the standard location where the man command searches for manual information.
-r Searches remotely for the manual information before checking the local sources. 
-t Formats the output using the troff utility. 

The Prerequisites to Using the man Command

Before you can access the manual pages on your Linux system, make sure you have the following:

  • A user account with root or sudo privileges
  • Access to terminal 

Structure of a Linux man Page

The Linux man command can generate very detailed output that can span several screens. Fortunately, this output has a standardized structure with the following sections. 

Important: Note that not all commands have all these headings because of the specific circumstances of a command. 

NAME

The standard name of the command or utility. This section also mentions any recognized shorthand for the command. 

SYNOPSIS

This section includes the syntax of the command and a description of the arguments, parameters, and options.

CONFIGURATION

This section is often present for commands that work on a hardware device. This section presents configuration options for the device.

DESCRIPTION

Presents the details of the command’s operations. The section starts with how the command works and then goes into the details of the options and flags you can use with the command. 

OPTIONS

If the command supports a long list of options, the manual pages often have a separate section for the description and explanation of these options.

EXIT STATUS

An optional section that lists the numeric codes that indicate the success or failure of the command. In most cases, there are two exit statuses – 0 for successful execution and >0 for failure.

RETURN VALUE

Mentions the possible values that the command returns after execution. This value is explicitly returned by the command. Note that not all commands return values. 

ERRORS

A list of errors you may see when using the command. Note that this section only covers the most frequently encountered errors.

ENVIRONMENT

A description of the environment required by the command. This section can include environment variables, required paths, and related information.

FILES

Lists the files and directories required for the execution of the command. This section lists the files the command requires as input.

VERSIONS

This optional section lists the available versions of the utility or command. 

NOTES

Contains information that couldn’t be included in other sections. Usually, you can find the required permission for the command and any dependencies.

BUGS

The section lists the commonly known bugs of the current version of the command or utility. 

EXAMPLE

This section presents several scenarios that highlight the command usage. Note that this section is not exhaustive because of the space constraints.

AUTHORS

This section names the people who created the utility and maintains the code base.

SEE ALSO

This optional section presents related commands that perform similar functions. 

Navigate the Output of the man Command

When you run the man command in the terminal, the command uses the system’s PAGER variable to help you go through several screens of the output. In most cases, the system’s PAGER variable is set to use less (/usr/bin/less). We recommend using the H key to get help with the less operations. 

You can use the following keys to navigate the Linux manual pages.

Navigate the man Command Output
Enter Move one line forward
Spacebar/pgdn Move one page/screen forward
B/pgup Move one page/screen backward
Q Quits the command output and returns to the terminal

In addition, you can use the UP and DOWN arrow keys or the MOUSE3 (the mouse wheel) to scroll through the screens.

How to Use the man Command to Get Information About Linux Commands

Let’s run through several scenarios to better understand the capabilities of the man command. 

Scenario #1: Use man to Get Information About a Command

Let’s start with the most common use of the command. Launch the terminal and run the following command to see the Linux manual entry for the ls command:

# man ls

man ls

You can see that the command uses the system’s pager (less) to display the information from the database.

Scenario #2: Get a Short Command Description

If you only need a quick introduction to a command, we recommend using the -f flag with the man command. For instance, run this command to get a concise description of the ls command:

# man -f ls

man -f ls

This command gives a one-liner description of the command, along with the section number from where the man command has extracted the information. 

Scenario #3: Get a List of All Pages About a Command

It is not uncommon to find multiple manual pages for a command. You can quickly get a list of these pages with the -f flag.

For instance, consider the following command that gets a list of all pages about the shutdown command:

# man -f shutdown

You can see that the man command finds two pages for the shutdown command. 

Scenario #4: Display all Related man Pages

In some cases, you may find that a command or a utility has multiple pages in different sections of the local Linux manual. For instance, consider the following command that shows information about the sleep command:

# man -a sleep

You can see that the output shows that man has found another entry (sleep(3)) for the sleep command.

Scenario #5: Get Information From a Specific Section

As we mentioned earlier, the Linux manual contains several sections, and a command may have entries in more than one section. Thai usually happens when a command can be used in several different “connotations”. 

Consider the shutdown command. This command can be used to shutdown the computer /server or a network connection. However, if you run the man command to get the information about shutdown, it only shows the content about the version that shuts down the computer. 

If you wish to get the information about the other use case of the shutdown command, we recommend using the -f flag to get the section numbers for the command. (see Scenario #3).

Now that you know that you need information from section 2, run the following command syntax to see the details:

# man [section] [command]

So, our command would be as follows:

# man 2 shutdown

Scenario #6: Display the Location of the Manual Pages

If you are interested in finding out the location of the contents of the manual pages for a command, we recommend the -w flag with the man command. For instance, run the following command to get the location for the shutdown command:

# man -w shutdown

You can extend this idea and get the location of the manual pages for all entries of a command by adding -a to the above command. For instance, we know that the shutdown command has two entries. The following command lists the location of both entries:

# man -wa shutdown

Scenario #7: Use a Regex to Search for a Command

You can use a regex to find all commands containing a string. A very common use case of this command is to find all commands containing a commonly known string in the name of the command or the description. 

Consider the following command that lists all commands that contain the string shutdown. Note that the output produces a short description of the commands.

# man -k shutdown

You can see that the command displays all commands and command descriptions that contain the string shutdown

Scenario #8: Run Case-sensitive Searches

By default, man queries are not case-sensitive to ensure that users get appropriate output despite misspelled commands. However, if you are searching for a command or package that has a mixed case, you may want to run case-sensitive searches. For this, use the following command syntax:

# man -I [exact command name]

Conclusion

We presented the man command in this tutorial that introduces the command and then goes into the details of several use cases to get the information you need. In our opinion, man is more than just a Linux command. It is a comprehensive resource for all users, not just the novices. You can get pertinent information that saves you time googling command options and syntax. 

In addition, we also discussed the structure of the output of the man command in the terminal/command line. We also mentioned the use of regular expressions to find the command you are looking for. This is important for users who have just started using the command and may get confused because of the information overload. 

FAQs

Q: What is the man command in the Linux environment?  

 The man command in Linux is used to display the manual pages for other commands, providing detailed information and usage examples.

Q: How can I access the Linux manual pages?  

 You can access the Linux manual pages by typing man followed by the command name in the terminal. For example, man ls will show the manual for the ls command.

Q: What is the purpose of the Linux manual?  

 The Linux manual provides comprehensive documentation for commands, system calls, library functions, and other aspects of the Linux operating system.

Q: How do I navigate within a man page in the Linux command line?  

 Within a man page, you can navigate using the arrow keys, Page Up and Page Down keys, and type q to quit the manual page.

Q: How do I find a specific section in a man page?  

 You can find a specific section in a man page by typing man section command. For example, man 2 shutdown open will show the section 2 manual page for the shutdown command.

Q: What information is typically included in a Linux command description in the manual?  

 A Linux command description in the manual typically includes the command’s syntax, options, detailed usage instructions, examples, and related commands.

Q: How can I search for a command if I don’t know its exact name using the Linux manual?  

 You can use the man -k command followed by a keyword to search for commands related to that keyword. For example, man -k copy will list commands related to copying.

Q: What is the significance of different sections in the Linux manual?  

The Linux manual is divided into sections, each covering a different aspect such as user commands (section 1), system calls (section 2), and library functions (section 3). This helps in organizing and finding relevant information efficiently.

Try this guide with our instant dedicated server for as low as 40 Euros