Linux man command is the number one helper to get more detailed information about Linux commands. There are different alternatives like info but man is a de-facto command for help. In this tutorial, we will look at various usage examples of the man command.
man Command Syntax
We will use following syntax for
man OPTION TERM
- TERM is the command, utility, topic we want to open its man page.
- OPTION is optional and used to provide optional to the man command.
View Man Page
The most common usage for man command is listing a command, tool, library usage simply. We will list the manual for
ls command like below.
$ man ls
Man Page Sections
Manual pages are categorized into sections. Each command, tool, library have a section. Categorization is made according to the relevance of command, tool, library. Each section has a number from 1 to 9.
- 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. man(7), groff(7)
- System administration commands (usually only for root)
- Kernel routines [Non-standard]
View Man Page For Specific Section
Sometimes there may be more than one tutorial about some expression. But those manual sections are different. For example
1 manual with the example below.
$ man 1 printf
List Sections For A Command
We may want to list sections for a command, library, or function. We will use man pages file to search and list. In the example, we will look
printf command manual pages.
$ man -aw printf
We can get section numbers from file name and directory name.
View All Man Pages For A Command
Another usage form for man pages is viewing all pages in a single command. Manual pages will be printed in a string mode. In order to quit from pages use
q shortcut. We will use
-a option to list all manual pages for
$ man -a printf
View Man Page In Browser
Another useful feature is viewing man pages in a browser. This is a more human-friendly way to read manuals but keep in mind that this will require a GUI desktop. First, we will set the
BROWSER variable for the command line interface bash and then use
-H parameter with the related command which is
printf in this situation.
$ export BROWSER=/usr/bin/firefox $ man -H printf
Search Man Page NAME Section
Man pages have different sections too. These are used to define part names. Here are these sections.
NAMEcontains the name of the command and short explanation
SYNOPSIScontains usage syntax
DESCRIPTIONcontains a more detailed explanation
OPTIONScontains all options about command
HISTORYcontains history about the command and persons
$ man -f printf
Search Man Page NAME and DESCRIPTION Section
In the previous example, we have only searched in the
NAME section. We may want to get more results and search in the
DESCRIPTION section too. We will provide
-k option like below.
$ man -k printf