The man Command in Linux

Find out more about commands and tools in Linux by using the man command.

man command in Linux

One of the most useful commands to learn about when dealing with Linux is the man command.

Using man, you can look up the manual pages for any tool or command that supports it.

A manual for a program can consist of up to nine different numbered sections. Only one of these sections need to be implemented for a program to have a valid manual.

These manual pages will describe how that command works and provide you with a rundown of all the options you can utilize. The pages can even provide information for programming libraries.

In this tutorial, we will be showing you the basics of using the man command on a Linux based system.

Syntax of the man Command

At its very basics, the man command is straightforward to use. It, at most, only takes in three different arguments. An option, a section number, and the name of a command/program/tool you want to look up.

man [OPTIONS] [SECTION NUMBER] [COMMAND/TOOL/PROGRAM]

To use the man command in Linux, you only need to specify the name of the command you want to look up.

For example, if we wanted to lookup more on the ls command, all we need to do is type in the following.

man ls

The man tool will automatically find the first available manual page for that command.

Looking up a Specific Section Using man

As we mentioned at the start of this guide, a manual can be divided into nine different sections.

By default, man will automatically pick the first available page, starting from section 1.

The man command gives us the ability to look up a specific section of a manual by specifying its number before the tool name.

man [SECTION NUMBER] [COMMAND/TOOL/PROGRAM]

Below we have a list of the section numbers that correspond to the type of information that is provided within it.

  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]

For example, if we were doing some programming and wanted to look up the library calls (Section 3) available for the printf tool, we can run the following command.

man 3 printf

Find out About the man Pages for a Command

If you are unsure of what sections would be available for a command, it is also possible to look these up.

To perform a lookup, we will need to make use of the whatis option (-f or --whatis).

man -f [COMMAND/TOOL/PROGRAM]

What this option does is print out a short description from the manual pages if its available. It will do this for each available section for the defined command.

For example, if we wanted to find out more about the manual pages provided for the printf command, we can try the following.

man -f printf

From this, you should end up seeing a response, as we have below.

printf (1)           - format and print data
printf (3)           - formatted output conversion

You can see that printf is mentioned alongside its section number, which is encased in brackets (( )). Finally, there is a short description describing what this function is for and what the manual page will be explaining.

Using the man command like this is the equivalent to using the whatis tool.

Browsing all Manual Page for a Command

The man command also gives you the ability to browse through all of the manual pages available for a specified program.

Doing this saves you the hassle of having to specify each section that you want to view manually.

To achieve this, we will need to make use of the -a option.

man -a [COMMAND/TOOL/PROGRAM]

After you have quit out of a manual page, the man tool will automatically ask you if you want to read the next one or quit out of the tool.

To show you this, let us run the following sample command, where we view all available manual pages for the printf package.

man -a printf

Once you exit the first page, you will see a prompt, as shown below.

$ man -a printf
--Man-- next: printf(3) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]

You can see that the next section number is specified with the brackets.

In addition to the details of the next page, you are given three different options.

Firstly, you can decide if you want to view the next page by pressing the ENTER key. Secondly, you can skip the page entirely by pressing CTRL + D. The third and final option you can exit out of the man tool by pressing CTRL + C.

Searching for Manual Pages Using Regular Expression

If you are looking for a manual page that contains a phrase or expression, then the man command also has a tool for that.

The option -k will search for the specified expression through all short description and page names. It will not search the manual pages themselves.

man -k [EXPRESSION]

Using this option will print out any matches to the terminal, specifying their name, section number, and short description.

We can see this behavior by looking up any other commands that contain the text printf.

man -k printf

Below is a small sample of what this command may return. Immediately you can tell that none of these options is printf itself. However, they do contain the word printf in their names.

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

Locating a Manual on the OS

If you want to find where the manual page is stored on your system you can utilize the -w option.

man -w [COMMAND/TOOL/PROGRAM]

This option will tell the man command to print out the location where the manual page for that program is stored.

For example, if we wanted to find out where the manual page for the printf command is stored, we can use the following command.

man -w printf

From this, we will get an absolute path to where the file resides within our system.

$ man -w printf
/usr/share/man/man1/printf.1.gz

Please note that this will output the manual page for the first section that it finds.

To get around this, we can either specify the section number for the manual that we want, like so.

man -w 3 printf

Alternatively, we could tell the man command to print the location of all of the available pages by using the -a option as well.

man -aw printf

Using man to Display the Manual to a Web Browser

We can also utilize the man command to display a manual page to a web browser that exists on our system.

Loading a manual in a web browser is useful for those that would rather not scroll through the pages within their terminal. To achieve this, all we need to do is utilize the -H option.

man -H[BROWSER COMMAND] [COMMAND/TOOL/PROGRAM]

For example, if we wanted to load the manual for printf in firefox, we can try running the following command.

man -Hfirefox printf

The man tool will convert the manual page into HTML then output it to the specified web browser.

Making the man command Case Sensitive

By default, the man command is case insensitive. This means that when it searches, the name PRINTF would be the same as printf.

In most cases, you should not need to make use of this. However, the man tool has the functionality to deal with situations where you have two programs with the same name.

You can tell man to be case sensitive by using the -I option.

man -I [COMMAND/TOOL/PROGRAM]

Learning More About the man Command

The man command is a powerful and versatile tool that can help make your life easier with dealing with new programs.

Even though we have gone through a few of the more useful options that man gives you, there is still plenty more you can learn.

The best way to learn about the vast range of options is to run the following command to load up the manual pages for man.

man man

Hopefully, at this stage, you will now understand how you can use the man command on Linux.

Be sure to check out our Linux commands section to find out about other useful Linux commands.

If you have run into any issues with this guide or feel like we missed something, feel free to leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *