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
Syntax:
man <TOPICNAME>
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) 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…
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 /usr/share/man/man1/printf.1.gz /usr/share/man/man3/printf.3.gz
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. View Man Page in HTML Format in a Browser
You can also view the man page in HTML format using any browser of your wish using “-H” argument. This will open the man page for printf command in firefox as HTML page.
$ export BROWSER=/usr/bin/firefox $ man -H printf
6. 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
7. 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.
8. 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.
Comments on this entry are closed.
Nice one,
gives more ideas on man pages.
Thank you The Geek Stuff.
Thanks – the “man -a” is a savior
Nice
how do you exit man?
I see (END) is highlighted – – but i can’t break out of man…..
Is there any way to list only the heading and sub-headings etc within a manpage? When confronted by an 8000 line manpage, I wish I could list just the headings as a rough table of contents – to help me find my info faster.
@vrn
It really depends upon what PAGER ( more or less ) you are using. In your case, I guess you are using less. Pressing ‘q’ will quit from the man.
@dru8274
I doubt whether it is possible to do that. If you want to navigate to a particular heading in man page, you can always search for it using / in case of less pager.
@Laksh It can be done, but I hoped to find a more elegant way than awk. This function generates the basic TOC for a manpage.
mtoc() {
man –ascii “$*” 2>/dev/null | awk ‘
BEGIN { a[“”]++ }
/^\s{0,4}\S/ && !($0 in a) { a[$0]++ ; b[i++]=$0 }
END { for (j=0 ; j<i ; j++) print b[j] }
' | less
}
Hi,
Thanks a lot…..
Excellent stuff! The perfect “man” for man 🙂
Thanks for the article..
Useful to know..
Awesome
Thanks so much. Great for you
Thanks so much really good one