Linux man Command Tutorial for Beginners (8 Examples)
On this page
- Linux man command
- Q1. How to use man command?
- Q2. How to make man display manual page from specific sections?
- Q3. How to lookup for manual pages and print short descriptions as well?
- Q4. How to make man display all manual pages for a given input?
- Q5. How to make man search considering input as regular expression?
- Q6. How to make man display location of manual pages?
- Q7. How to make man display manual pages in Web browser?
- Q8. How to make man command case sensitive?
A very useful aspect of the Linux command line is that the documentation for almost all command line tools is easily accessible. These documents are known as man pages, and you can easily access them through the command line using the man command.
In this tutorial, we will discuss the basics of man using some easy to understand examples. But before we do that, it's worth mentioning that all examples in this article have been tested on Ubuntu 16.04 LTS machine.
Linux man command
The man command gives users access to manual pages for command line utilities and tools. Following is the syntax of this command:
man [command/tool name]
And here's how man's own manual page describes it:
man - an interface to the on-line reference manuals
man is the system's manual pager. Each page argument given to man is
normally the name of a program, utility or function. The manual page
associated with each of these arguments is then found and displayed. A
section, if provided, will direct man to look only in that section of
the manual. The default action is to search in all of the available
sections following a pre-defined order ("1 n l 8 3 2 3posix 3pm 3perl 5
4 9 6 7" by default, unless overridden by the SECTION directive in
/etc/manpath.config), and to show only the first page found, even if
page exists in several sections.
The table below shows the 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 eg /etc/passwd
7 Miscellaneous (including macro packages and conventions), e.g.
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
A manual page consists of several sections.
Conventional section names include NAME, SYNOPSIS, CONFIGURATION,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUE, ERRORS, ENVIRONMENT,
FILES, VERSIONS, CONFORMING TO, NOTES, BUGS, EXAMPLE, AUTHORS, and
Following are some Q&A-styled examples that should give you a good idea on how the man command works.
Q1. How to use man command?
The basic usage of man is very simple - just run the command with the name of the tool whose reference manual you want to access.
man [command/tool name]
Q2. How to make man display manual page from specific sections?
As already mentioned in the beginning, all available manual pages are segregated into sections, and there are sections that contain man page entries of same name. To make things easier for you, the man command lets you directly access manual pages from specific sections, something which you can do by just specifying the section number before the command/tool name.
man [section-num] [command/tool name]
man 3 printf
Q3. How to lookup for manual pages and print short descriptions as well?
While going through Q&A 2, one may ask how to remember section numbers for manual entries with the same name. Well, you don't have to do that as there exists a command line option 'f' that allows man to display all manual pages that match the name in the input.
man -f printf
Here's the outptut the above command produced on my system:
So you can see all entries with name 'printf' - along with section numbers - were displayed in the output.
Q4. How to make man display all manual pages for a given input?
Now, what if you want man to display one by one all manual pages corresponding to a given input? Well, that's possible, and you'll have to use the -a command line option for it.
For example, if you want to serially view all man pages for 'printf', you can do that in the following way:
man -a printf
The above command will first open the printf man page from section 1, and when you quit it, the command will ask you if you want to view the next 'printf' man page.
Q5. How to make man search considering input as regular expression?
In case you want the man command to search and list manual pages by considering input as a regular expression, you can do that using the -k command line option.
man -k [command/tool name]
man -k printf
Here's the output the above command produced on my system:
Q6. How to make man display location of manual pages?
In case the requirement is to only know the location of manual pages, you can force man to do this by using the -w command line option.
man -w [command/tool name]
man -w printf
Following is the output this command produced on my system:
Q7. How to make man display manual pages in Web browser?
Use the -H command line option for this.
man -H[browser-command] [command/tool name]
man -Hfirefox printf
Q8. How to make man command case sensitive?
By default, the man command ignores case while searching for manual pages. However, if you want, you can enable case-sensitivity using the -I command line option.
man -I [command/tool name]
So you can see man is an extremely important command that users - both newbies and pros - should know how to use. We've just scratched the surface here, as the tool offers a lot of features. Practice these first, and when you are done, head to the man's manpage for more info.