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.
Table of Contents
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...
ShellScriptHere is how you can check the manual for the ls
command:
man ls
ShellScriptWhen 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.
In the lower section of the manual, you can also find AUTHOR, REPORTING BUGS, COPYRIGHT, and SEE ALSO.
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:
- Executable programs or shell commands
- System calls (functions provided by the kernel)
- Library calls (functions in the C library)
- Special files (e.g., device files)
- File formats and conventions
- Games
- Miscellaneous
- System administration commands
- Kernel routines
If you want to view information from a specific section, you can specify the section number.
man [section number] [command]
ShellScriptFor example, here’s how you can check the format of the /etc/passwd
file:
man 5 passwd
ShellScriptThis 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.
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:
- Run
man ls
- 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.
Navigating multiple pages
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]
ShellScriptHere’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
ShellScriptThis 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.
-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]
ShellScriptHere’s how to search for manuals related to the keyword “copy.”
man -k copy
ShellScriptThis command outputs all commands and descriptions related to the keyword “copy,” as shown below.
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
ShellScriptAdditionally, 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.