Man Command in Linux

FREE Online Courses: Click, Learn, Succeed, Start Now!

In this article, we will learn everything about the man command in Linux. We will start right from the basics like what the man command is, What information the man command shows, and only then go to the practical sections where we will look at some of the most beautiful examples of the man command in the terminal of Ubuntu 20.04.

What is linux man command?

Man is the abbreviation for manual. It is a command-line-based utility in Linux-based operating systems that helps in displaying the manual of various commands used in the operating system.

We all know that The Linux operating system is absolutely brimming with different commands to use. There are hundreds of commands for various different uses. Each of these commands, also has lots and lots of options to use, but the million-dollar question is how do you remember which command is for what, and under which scenarios do you use the various options?

Well, there is a catch, you actually don’t! Why? Because Linux has a ” man ” command that prints the manual any command you specify. This manual consists of lots of invaluable information like how to use the options of the command, various syntaxes of the command, definitions of the command, what it is used for and so much more!

That is why learning how to use the man command in Linux will grant you the instant ability to learn how to use any other Linux command. Now, hopefully, you don’t have to keep googling to understand command and its options as you can straight away get information from the Linux terminal.

Sections of a manual

The default setting of the man command is to look in all the available sections of the manual and shows the first match. However, if you provide the section number, the man command will only search in that specific section. There are 9 sections of the manual, let us look at each one in brief.

1. General commands

This section consists of the commands used in the terminal.

2. System calls

This section consists of the functions the kernel provides.

3. Library functions

This section consists of the functions in program libraries.

4. Special files

This section consists of the devices found in /dev and related drivers.

5. File format and conventions

This section consists of different File formats like etc/passwd.

6. Games

This section consists of the descriptions of commands that display database quotes.

7. Miscellaneous

This section consists of the various descriptions, including macro packages and conventions, boot parameters, and others.

8. System administration commands

This section consists of the Commands mostly reserved for root.

9. Kernel routines

This section consists of Information about internal kernel operations.

What information does the man command show?

The saw that the man commands shown a lot of invaluable information, but what exactly does it show? Well, here is a list of headings that a manual for a command may contain:

1. Name – Shows the name of the command
2. Synopsis – Gives the syntax of the command
3. Configuration – This shows you the configuration details for a device
4. Description – Shows a brief description of the command
5. Examples – displays several examples showing you how to use the command
6. Options – gives information about the options used with the command
7. Exit status – shows the list of possible exit statuses of the command
8. Environment – shows the lists of environment variables used by the command
9. Files – shows the lists of files used by the command
10. See also – shows a list of related or similar commands
11. Authors – names of the people who wrote or maintain the command
12. History – shows a brief history of the command development
13. Notes – Shows various notes like permissions, dependencies, etc
14. Bugs – lists the known issues in this program version.

Syntax of the man command in Linux

The syntax of the man command is really simple, it is as shown below:

man <options> <section number> <command name>

Let us take a closer look at the field present in the syntax of the man command.

1. <options>

This field takes in a range of options that specify how the man option must work and print the output.

2. <section number>

This field specifies the section in which to look for the man page.

3. <command name>

This field specifies the name of the command you want the manual for.

Options used with linux man command

In typical Linux fashion, just like every command has lots and lots of commands, the man command also has a truckload of options that specify how the man option must work and print the output. Let us look at these options:

1. -C

This option uses the user configuration file rather than the default of ~/.manpath. You can also write this option as “–config-file”

2. -d

This option prints the debugging information. You can also write this option as “–debug”

3. -D

This option resets the man command’s behavior to its default. You can also write this option as “–default”

4. –warnings

This option performs sanity checks on the source text of manual pages.

5. -f

This option displays a short description from the manual page. You can also write this option as “–whatis”

6. -k

This option searches the short manual page descriptions for keywords and displays any matches. You can also write this option as “–apropos”

7. -K

This option Search for text in all manual pages. You can also write this option as “–global-apropos”

8. -l

This option formats and display local manual files instead of searching through the system’s manual collection. You can also write this option as “–local-file”

9. -w

This option doesn’t actually display the manual pages but prints the location(s) of the source nroff files that would be formatted. You can also write this option as “–where-cat”

10. -W

This option does not actually display the manual pages, but prints the location(s) of the cat files that would be displayed. You can also write this option as “–catman”

11. -R

This option outputs its source converted to the specified encoding instead of formatting the manual page in the usual way. You can also write this option as “–recode”

12. -m

This option determines your current locale by a call to the C function setlocale which interrogates various environment variables, possibly including $LC_MESSAGES and $LANG.

13. -M

This option accesses other operating systems’ manual pages if this system has access to them. You can also write this option as “–system”

14. -i

This option Ignore the case when searching for manual pages. You can also write this option as “–ignore-case”

15. -I

This option Search for manual pages case-sensitively. You can also write this option as “–match-case”

16. –regex

This option shows all the pages with any part of either their names or their descriptions matching each page argument as a regular expression, as with apropos.

17. –wildcard

This option shows all pages with any part of either their names or their descriptions matching each page argument using shell-style wildcards, as with apropos(1) –wildcard.

18. -a

This option forces the man command to display all the manual pages with names that match the search criteria. You can also write this option as “–all”

19. -u

This option causes the man command to perform an `inode level’ consistency check on its database caches to ensure that they are an accurate representation of the filesystem. You can also write this option as “–update”

20. -H

This option causes Groff to produce HTML output and will display that output in a web browser.

21. -h

This option prints the help menu of the man command as shown below:

help menu of the man command

21. -v

This option prints the information about the version of the man command:

version of the man command

Now that we have laid down the fundamentals, let us look at some amazing practical examples of how to use teh man command in the terminal of Ubuntu 20.04.

Manual of the man command

It would be a shame if we learn at the manual command and we don’t actually see the manual of the man command, so let’s kick off the examples by looking at the manual command by using the command “man man”.

manual  of the man command

Looking for man pages

To search for the manual pages and not actually open them, use the option “-f” as shown:

man -f <command name>

looking for man pages

Displaying man pages from specific sections

If you want the man command to display manual pages from specific sections use the following syntax, where you can specify the section number:

man [section number] [command name]

displaying man pages from specific sections

For example, in the above screenshot, the manual command displays the manual of the sleep command in section number 3 and not the one in section number 1.

Display man pages in a browser

The manuals of most commands are really long and are difficult to scroll through to find the information you need. That is why the man command allows users to display man pages in a browser to find information easily. However, it is not as simple as it sounds. You will first have to install the Groff package by using the command:

sudo apt-get install groff

installing groff to display manual pages in the internet

Once the installation was successful, set the default browser as Firefox by running the command:

export BROWSER=firefox

setting the default browser as firefox

Now you are all set to use the manual pages through the browser, simply use the option “-H” as shown below:

man -Hfirefox <command name>

viewing manual on the internet

In the above screenshot, the manual pages for the vmstast command were obtained upon typing the command “man -Hfirefox vmstst”. As you can see it has internal links that lead you directly to the topic of your choice!

Displaying man pages along with short descriptions

To display (and not open) the man pages along with a short description of what it is about, use the option “-f” as shown below:

man -f <command name>

displaying man pages along with short descriptions

Display all the man pages

To display all of the man pages, pair the man command with the option “-a” as shown:

man -a <command name>

display all the man pages

Searching by Considering Input as a Regular Expression

If you want to search the short command descriptions and manual page names for a specified keyword as a regular expression, pair the man command with the option “-k” as shown:

man -k <command name>

searching by considering input as a regular expression

Display the location of the man pages

If you want to display the location of the man pages, pair the man command with the option “-w” as shown:

man -w <command name

display the location of the man pages

Enabling case sensitivity

By default, the man command is case-insensitive. However, if you want search for manual pages using case-sensitivity, use the option “-I” as shown below:

man -I <command name>

enabling case sensitivity

Summary

As you have seen, the man command is a very simple yet extremely helpful command that gives us complete information about a specific command. Yoou have now learned what the man command is, why it is used, what are the different sections of a manual, what are the topics the man command gives information about and the syntax and options used with the man command. In the end, we have also learnt some practical examples of the man command.

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *