Home FAQ How To View A Specific Section In Man Pages In Linux
View A Specific Section In Man Pages In Linux

How To View A Specific Section In Man Pages In Linux

By sk
186 Views

When looking for the usage of a Linux/Unix command, you actually don't have to Google or search in the discussion forums, wiki pages, blogs or any offline/online resources. Everything is documented in the manual pages (shortly man pages) of the command. You just need to learn to use man pages efficiently in-order to get the details of a command or its options/flags easily and quickly. Today, I will share a lesser-known man page trick i.e. how to view a specific section in man pages in Linux and Unix.

Man page default structure

A man page consists several different sections, organized with headings for each section, such as NAME, SYNOPSIS, CONFIGURATION, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUE, ERRORS, ENVIRONMENT, FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and SEE ALSO. Each man page has its command name followed by the section number in parenthesis.

Here is the list of section numbers of the manual followed by the types of pages they contain:

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 e.g. /etc/passwd.
6   - Games.
7   - Miscellaneous (including  macro  packages  and conventions), e.g. man(7).
8   - System administration commands (usually only for root).
9   - Kernel routines [Non standard].

Some pages have all of these sections and some does not have. Now let us see how to view a specific section of a command's man page.

View A Specific Section In Man Pages In Linux

Let us open a man page of a command, for example uname.

$ man uname

Scroll down the end of the man page and you will see references to other commands.

[...]
SEE ALSO
       arch(1), uname(2)
[...]

uname command man page

Do you see the all those numbers trailing the commands at the end? You will see one or more reference commands with numbers in parenthesis at the end of almost all commands' man pages. These numbers indicates the specific section of the command's man page you want to look at. In other words, the number corresponds to what section of the manual that page is from.

To tell man explicitly to open the section 2 of the uname command, simply run:

$ man 2 uname

Or,

$ man uname.2

In the following screenshot, the left side Terminal window shows the output of "man uname" command. The right side of the Terminal window shows the output of "man 2 uname" (i.e. section 2 of uname) command.

View A Specific Section In Man Pages In Linux

Please note that when we run the man command without any numbers, it is usually equivalent of:

$ man 1 <command>

Some man pages doesn't have a specific section. In that cases, you don't get anything back when trying to view the man page with section number. For example, I run the following command to see the 5th section of uname command:

$ man 5 uname

Since uname command doesn't has section 5, I get the following output:

No manual entry for uname in section 5
See 'man 7 undocumented' for help when manual pages are not available.

Show all sections in a row

Like I already said, a specific command's man page has many sections. To view every matching page in a row, use -a flag like below.

$ man -a uname

Press q to quit one section and move to the next section.

Show all commands matching to a string with section numbers

We can search for man pages containing a search string using -k flag. So if you want to retrieve all section numbers of specific command in the man page, use -k option like below.

$ man -k uname

Sample output:

arch (1)             - print machine hardware name (same as uname -m)
oldolduname (2)      - get name and information about current kernel
olduname (2)         - get name and information about current kernel
uname (1)            - print system information
uname (1posix)       - return system name
uname (2)            - get name and information about current kernel

As you see in the above output, we listed all commands(i.e. substrings) that matches to the given keyword string. To strictly limit the search within the matched string, use:

$ man -k '^uname'

Sample output:

uname (1)            - print system information
uname (1posix)       - return system name
uname (2)            - get name and information about current kernel

You can alternatively use -f flag.

$ man -f uname

Sample output:

uname (1)            - print system information
uname (2)            - get name and information about current kernel
uname (1posix)       - return system name

For more details, please look at the man pages of "man".

$ man man

Also, see other help sections for man pages.

$ man -k man
$ info man

Recommended read: 


Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More