Sunday, September 29, 2013

Linux Man Command Example to View Man Pages

In UNIX and Linux distros, command line programs come with their own documentation called manual pages or man pages.
Man pages are generally written by the developer of the corresponding program. Generally the man pages are divided into number of sections.
The following is the list of all available man sections. Every section has a unique number and contains only a specific type of man pages. For example man section number 3 contains only man pages of library calls.

  • 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



1. View Man Page of an UNIX Command

 To read the man page of an UNIX 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 Commands     PASSWD(1)
       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…

2. 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.

3. 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
From the above output, we can know that there are 2 printf manuals, one in “Commands” section and another one in “Library calls”. So, you can do the following man command to view both the man pages.

$ man printf
$ man 3 printf

4. 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

The above command will display the man page of printf(1) command 
first. When you press “q” and press “Enter”, it will display the man 
page of printf(3) library function.

5. 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
printf (1)           - format and print data
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.

6. 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
asprintf (3)         - print to allocated string
dprintf (3)          - print to a file descriptor
fprintf (3)          - formatted output conversion
fwprintf (3)         - formatted wide-character output conversion
printf (1)           - format and print data
printf (3)           - formatted output conversion
snprintf (3)         - formatted output conversion
sprintf (3)          - formatted output conversion
The above command will search for the keyword “printf” as regular expression and display all the man pages that matches the keyword.

"Please feel free to ask queries and comment"
Thank you ..... Bye...