The man command in Linux/Unix

When you buy a new home appliance, it is accompanied by a user manual that explains the functions of the appliance. Similarly, when you download and install a new package for Linux, the user manual for the program is automatically installed in your system. The man command is what you can use to read through the manual pages. Here man stands for manual, as in “user manual”.

What is a “man” page?

Documentation created by the developer explaining usage, available options, and sometimes listing some easter egg functionalities for a package. The man page is divided into 8 sections:

  • Section 1: General commands
  • Section 2: System calls
  • Section 3: Library functions
  • Section 4: Special files
  • Section 5: File formats and conventions
  • Section 6: Games and screensavers
  • Section 7: Miscellaneous
  • Section 8: System administration commands and daemons

The man pages make use of a terminal pager program such as more or less to display the content of the manual.

Common Usage of man Command in Linux

To read a manual page, you will write:

[root @ shell]# man (package name)

For example, if you need to read more about the Nginx server, write:

[root @ shell]# man nginx

The output you receive will be similar to the one below based on the package version.

Man Page Nginx
Man Page Nginx

Finding a man page

man pages are not always named in the way the command is used. What can you do when you do not know the exact name of the man page you want to view? In such cases, you can use the keyword search functionality within the man command. You can access this functionality with the -k option which stands for “keyword”.

[root @ shell]# man -k crypt
Man K Option
Man K Option

This will give you a list of all the man pages that are a keyword match. In the above case, I get a list of all the man pages that contain the word “crypt” in them.

Jump to a specific section within the man page

If you want to jump to a section on a man page without having to scroll through, you can add the section number to the command right after the word man. You can refer to the section numbers at the beginning of the page. So for example, if you want to view only the general commands of a package (which is section 1), you can write:

[root @ shell]# man 1 ls
Man Skip To Section
Man Skip To specific Section

Writing a man page to a file

If you want to export a man page to a file without printing it to the standard output of the terminal, we can make use of the output redirect operator (“>”). What this does is read the output, and save the entire output in a file that you specify. This operator can be used with any command in Linux to save their output for later use.

Let’s see a quick example of how this can be achieved.

[root @ shell]# man ls > ls.conf
Writing Man Page To A File
Writing Man Page To A File

In the above example, I’ve shown how the file “ls.conf” gets created automatically. Once you save the file, you can make use of the “cat” command to output the contents of the file that you want. In this case, you can see that the output of the “cat ls.conf” command is an exact replica of the man page.

Configuration files for the man command

Like with almost every command in Linux, you have a .conf file for the man command in the /etc/ folder.

  • /etc/man.conf – This is an optional configuration file in which a user can configure the paths and the output formatting options for the man. The MANPATH configuration in this file overrides the manpath.config.
  • /etc/manpath.config – The manpath configuration file is used by the manual page utilities to indicate which manual page hierarchies (manpaths) are to be treated as system hierarchies and to assign them directories to be used for storing cat files. This is primarily the configuration file for the man-DB which stores man command related cache. If the man.conf file exists with MANPATH configured, this file will adhere to the paths in that file.

Have a look at some silly man pages!

The man page documentation is filled with hidden sarcastic lines put in by developers for fun. If you’re a geek, you surely like to play around, right? Go ahead and download the asr-manpages package using your package manager. Once installed, try a few of these manpages to have a good geeky laugh!

  • man 8fun guru
  • man 8fun nuke
  • man 8fun bosskill
  • man 8fun knife
  • man 8fun ctluser
  • man 8fun luser
  • man 2fun people
  • man 1fun lart
  • man 1fun c
  • man 1fun slave
  • man 1fun sysadmin

If you’re not able to install the package, just do a quick Google search of the exact commands above. Man pages are also available on the internet as an HTML page so you should be able to find the same man document online too.

Conclusion

Man pages are a helpful bunch of documents for anyone who’s stuck while using a Linux utility. If you want to know more about “man”, there’s a man page for that too. Just enter “man man” in the command line and you should see the man page for the man command.

Getting familiar with the pages of your regularly used commands can help you become far more efficient in your day-to-day activities. And who knows, while reading through them you might come across some really interesting things which are not very well known yet!