Thursday, 3 October 2013

Centos 6/RHEL using man pages

In Centos 6/RHEL and other Linux distros, command line programs come with their own documentation called manual pages or man pages. These are generally written by the developer of the corresponding program and are divided into number of sections.

Below is the list of available man sections. Every section has a unique number and contains only a specific type of man pages.
  • 1 – Executable programs or commands
  • 2 – System calls ( functions provided by the kernel )
  • 3 – Library calls ( functions provided by the library )
  • 4 – Special files
  • 5 – File formats and conventions ( configuration files )
  • 6 – Games
  • 7 – Miscellaneous
  • 8 – System administration commands
Syntax:

$ man <topicname>

View the Man Page of a command

To read the man page of an Linux command, pass the command name as the argument to the man. The following will display the man page for passwd command.

$ man passwd
PASSWD(1) User utilities  PASSWD(1)
NAME
    passwd - change user password

Some topics may even have man pages in more than one section. In such a case, man command will display the page which has lower section number.
In this example, the passwd command has manual pages in multiple sections. But, by default, it displays the man page from the section 1.
The “PASSWD(1)” shown in the 1st line of the man command output indicates that it is displaying the man page from section 1. The man page output displays the command name, syntax of the commands, description of what the command does, options provided by the command, etc…

View Man Page from a Specific Section

To read the man page from a particular section, provide the section number as follows. The passwd command has man page in both section 1 and section 5. By default, if you don’t specify the section number, it will display man page from section 1.
To display man page from section 5, specify the section number as shown below.

$ man 5 passwd

Now it will display the manual page for /etc/passwd configuration file, since the section number 5 is for File Formats and Conversions.

List Available Man Sections for a Command

You can also list all the available sections on a particular topic using -aw option.

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

View All Man Pages for a Command – Display All Sections

To view all the man pages for a particular topic, use the “-a” option. You’ll see the lowest-number man page first. When you exit that page, and press “Enter” the next man page will appear.

$ man -a printf

Change the Default Pager used by Man Command

By default man command will use the $PAGER environment variable to identify which pager to use for showing output. User can change the pager in which they prefer to see the man page using ‘-P’ option.
The following command will display the man page using more command pager.

$ man -P more printf

Search Man Page against NAME Section

To search the man page against NAME section, use “-f” option as shown below.

$ man -f printf

printf (3) - formatted output conversion

This is equivalent to using whatis shell command.

The above command, searches the manual page names, and displays the description for the given topic if the manual page names, matches with the given topic. You can also pass multiple topics in the same command line.

Search Man Page against NAME and DESCRIPTION Section

To search the man page against NAME & DESCRIPTION section, use “-k” option. It is equivalent to using “apropos” shell command.

$ man -k printf

printf               (1)  - format and print data
printf [builtins]    (1)  - bash built-in commands, see bash(1)
printftest           (6)  - tests the vgagl gl_printf function
set_matchpathcon_printf [set_matchpathcon_flags] (3)  - set flags controlling the operation of matchpathcon or matchpathcon_index and configure the behaviour of validity checking and error displaying

The above command will search for the keyword “printf” as regular expression and display the man pages that match the keyword.