Linux Command man and 2 Key Options

The Linux command man is a tool that provides detailed explanations of specific commands, with “man” being short for “Manual.” When using various commands in Linux, understanding their functionality, usage, and options is essential. However, it can be challenging to remember every command. This is where the man command becomes useful. In this post, we will explore the basic usage of the man command, its options, and practical ways to make the most of it in your daily tasks.

What is the Linux command man?

The man command in Linux displays manual pages that provide usage instructions for various commands. It is primarily used in the terminal, and in addition to commands, it also offers information about configuration files and system calls (System Calls). For example, if you’re curious about the usage of the ls command, you can type man ls in the terminal to get all the information about that command.

Basic format of the man command

The basic method to use the Linux command man is as follows:

man [option] [section] page...
ShellScript

Here is how you can check the manual for the ls command:

man ls
ShellScript

When you run the command above, you will see the explanation, usage, and options for the ls command. You can check sections such as NAME, SYNOPSIS, and DESCRIPTION, as shown in the image below.

Figure 1. Top section of the Linux command man ls output
Figure 1. Top section of the Linux command man ls output

In the lower section of the manual, you can also find AUTHOR, REPORTING BUGS, COPYRIGHT, and SEE ALSO.

Figure 2. Bottom section of the Linux command man ls output
Figure 2. Bottom section of the Linux command man ls output

The manual page is usually organized into the following sections:

  • NAME: The name of the command and a brief description
  • SYNOPSIS: Basic usage and format of the command
  • DESCRIPTION: A detailed explanation of the command, often including options
  • OPTIONS: Detailed usage of the available options
  • ENVIRONMENT: Variables that may affect the execution of the command
  • AUTHOR: Information about the developers of the command
  • REPORTING BUGS: Instructions on how to report bugs
  • COPYRIGHT: License and copyright information
  • SEE ALSO: Related commands or additional pages to read

Main uses of the man command

Searching specific sections

The Linux manual pages are divided into multiple sections. While the default behavior is to show the command-related page, if you want information on configuration files or system calls, you can specify a particular section. The main sections are as follows:

  1. Executable programs or shell commands
  2. System calls (functions provided by the kernel)
  3. Library calls (functions in the C library)
  4. Special files (e.g., device files)
  5. File formats and conventions
  6. Games
  7. Miscellaneous
  8. System administration commands
  9. Kernel routines

If you want to view information from a specific section, you can specify the section number.

man [section number] [command]
ShellScript

For example, here’s how you can check the format of the /etc/passwd file:

man 5 passwd
ShellScript

This command displays the manual page related to the format of the /etc/passwd file. You can see “PASSWD(5)” in the top left corner, indicating that this is from section 5. At the top center, it also notes that this is a guide for “File Formats and Configuration.” The DESCRIPTION section explains the format of the passwd file in detail.

Figure 3. Searching a specific section with the Linux command man
Figure 3. Searching a specific section with the Linux command man

Searching by keyword

If you want to search for a specific keyword within the manual page, you can use the / character. For example, if you want to find the word “date” in the man ls output, follow these steps:

  1. Run man ls
  2. Enter /date and press Enter

This allows you to jump to any part of the page that contains the word “date.” The keyword will be highlighted, making it easy to find.

Figure 4. Searching for keywords in the Linux command man
Figure 4. Searching for keywords in the Linux command man

If the manual page does not fit on one screen, you can scroll through the pages. The commonly used keys are as follows:

  • Space or Page Down: Move down one screen
  • b or Page Up: Move up one screen
  • q: Quit the manual page

You can also use the arrow keys to move one line at a time.

Options of the man command

-f option: Simple description output

If you want a simple description of what a command does, you can use the -f option. This works the same as the whatis command, providing a brief description of the command or file. If you want to learn more about the apropos command, please refer to “Linux Command whatis: 2 Ways of Usage“.

man -f [command]
ShellScript

Here’s how to view a brief list for the passwd manual page. While this may not be particularly useful for commands with only one instance, it is helpful when there are multiple commands or files with the same name.

man -f passwd
ShellScript

This command provides a brief description of the passwd command, the OpenSSL application command passwd, and the /etc/passwd file. The section numbers are shown in parentheses. If no section is specified, the manual from section 1 is shown by default. You can specify a section to view a particular manual.

Figure 5. Viewing a simple description with the Linux command man
Figure 5. Viewing a simple description with the Linux command man

-k option: Search manuals by keyword

If you can’t remember the exact name of a command or function, you can use the -k option to search for a keyword. This works the same as the apropos command. If you want to learn more about the apropos command, please refer to “Linux Command apropos and 3 Options“.

man -k [keyword]
ShellScript

Here’s how to search for manuals related to the keyword “copy.”

man -k copy
ShellScript

This command outputs all commands and descriptions related to the keyword “copy,” as shown below.

Figure 6. Searching manuals by keyword with the Linux command man
Figure 6. Searching manuals by keyword with the Linux command man

Cautions when using the man command

The man command is pre-installed on most Linux distributions, but in certain situations, the manual pages might not be installed. In such cases, you need to install the relevant packages. For example, in Debian-based systems, you can install the man-db package as follows:

sudo apt install man-db
ShellScript

Additionally, manual pages are often provided in English, but many Linux distributions offer manuals in various languages, so you don’t need to worry too much.

Summary

The Linux command man is one of the essential tools that every Linux user should know. It provides detailed manuals for each command, making it very useful when learning new commands or using unfamiliar ones. By effectively utilizing various options such as section search and keyword search, you can efficiently find the information you need.

Instead of searching the internet every time you encounter an unfamiliar command, try using the man command first. This will greatly help improve your Linux skills.

References

Leave a Comment