man command in Linux with Examples
man command in Linux is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command which includes
NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and
Every manual is divided into the following sections:
- Executable programs or shell commands
- System calls (functions provided by the kernel)
- Library calls (functions within program libraries
- Special files (usually found in /dev)
- File formats and conventions eg /etc/passwd
- Miscellaneous (including macro packages and conventions), e.g. groff(7)
- System administration commands (usually only for root)
- Kernel routines [Non standard]
$man [OPTION]... [COMMAND NAME]...
Options and Examples
1. No Option: It displays the whole manual of the command.
$ man [COMMAND NAME]
$ man printf
In this example, manual pages of the command ‘printf‘ are simply returned.
2. Section-num: Since a manual is divided into multiple sections so this option is used to display only a specific section of a manual.
$ man [SECTION-NUM] [COMMAND NAME]
$ man 2 intro
In this example, the manual pages of command ‘intro‘ are returned which lies in the section 2.
3. -f option: One may not be able to remember the sections in which a command is present. So this option gives the section in which the given command is present.
$ man -f [COMMAND NAME]
$ man -f ls
In this example, the command ‘ls‘ is returned with its section number.
4. -a option: This option helps us to display all the available intro manual pages in succession.
$ man -a [COMMAND NAME]
$ man -a intro
In this example you can move through the manual pages(sections) i.e either reading(by pressing Enter) or skipping(by pressing ctrl+D) or exiting(by pressing ctrl+C).
5. -k option: This option searches the given command as a regular expression in all the manuals and it returns the manual pages with the section number in which it is found.
$ man -k [COMMAND NAME]
$ man -k cd
The command ‘cd‘ is searched in all the manual pages by considering it as a regular expression.
6. -w option: This option returns the location in which the manual page of a given command is present.
$ man -w [COMMAND NAME]
$ man -w ls
The location of command ‘ls‘ is returned.
7. -I option: It considers the command as case sensitive.
$ man -I [COMMAND NAME]
$ man -I printf
The command ‘printf‘ is taken as case-sensitive i.e ‘printf‘ returns the manual pages but ‘Printf‘ gives error.