man Command in Linux with Examples

November 27, 2024

Introduction

The man command is a built-in manual for using Linux commands. It allows users to view the reference manuals of a command or utility used in the terminal. The man page (short for manual page) includes a command description, applicable options, flags, examples, and other informative sections.

In this tutorial, you will learn to use the man command in Linux.

How to use the man command in Linux.

Prerequisites

  • A machine running Linux.
  • Access to the terminal.
  • An account with sudo or root privileges.

Linux man Command Syntax

The basic man command syntax is:

man [options] [section number] [command name]

The [options] in the man command allow users to modify its behavior or adjust its output format. The [section number] specifies which section of the manual to search for the desired command.

The [command name] identifies the specific command, program, or file for which the manual page is to be viewed, providing detailed documentation on its usage.

The manuals are categorized into two distinct parts:

  • Output sections. Sections of an individual man page.
  • Manual. Numbered categories.

Below is a detailed explanation of each aspect.

Linux man Command Output Sections

When you view a specific manual page, the content is structured into output sections to present detailed information in a logical format. The sections are:

  • NAME. The command or function name and a brief description. Provides a concise overview of the topic covered by the manual page.
  • SYNOPSIS. The syntax for using the command or function, including options and arguments.
  • DESCRIPTION. A detailed explanation of what the command or function does. Provides context, examples, and use cases.
  • OPTIONS. A list of options to be used with the command and their meanings.
  • EXIT STATUS. The exit codes returned by the command to indicate success or errors. Helps in debugging and scripting.
  • EXAMPLES. Practical examples demonstrating the usage of the command.
  • FILES. A list of related files, such as configuration or log files.
  • SEE ALSO. References to related commands or topics.
  • BUGS. Known issues or limitations of the command or program.
  • COPYRIGHT. Licensing and copyright details.
  • AUTHORS. Credits to the developers or contributors.

Note: Pages contain varying number of sections depending on the man page contents.

Types of Sections in man Command Manuals

The manual sections categorize documentation into groups based on the type of information provided. Each section is associated with a specific type of content. There are nine of these sections:

  • Executables or shell commands. Commands that can be executed directly in the terminal shell.
  • System calls. Functions provided by the Linux kernel, such as open, read, and write.
  • Library calls. Functions within libraries, such as the C standard library, like <b>print</b>if. Developers use these calls to leverage prewritten functionalities available in libraries.
  • Special files. Descriptions of device files, usually found in /dev. These files represent hardware or virtual devices used for communication between the system and peripherals.
  • File formats and conventions. Details on configuration files and their structure, such as /etc/passwd.
  • Games. Documentation for games and recreational programs.
  • Miscellaneous. Topics that don't fit into other sections, such as macro packages and conventions.
  • System administration commands. Commands primarily used by system administrators, such as iptables and mount. These commands require elevated privileges and are used to manage the system and its services.
  • Kernel routines. Intended for developers working with the Linux kernel. Contains documentation of kernel-level routines and functions.

Linux man Command Options

The man command has several options that modify how it works. The following table explains these options:

OptionDescription
-k Searches the manual page descriptions for a keyword.
-f Displays the section number and a brief description of the specified command.
-a Displays all available manual pages for the specified command.
-w Shows the path to the manual page file without displaying its contents.
--help Displays a help message listing available options for the man command.
-P [pager] Specifies the pager program to use for displaying manual pages.
-s [num] Searches only within the specified manual section.

To navigate a manual page, use Spacebar to move forward one page, Enter to move forward one line, B to move backward one page, and Q to quit the manual viewer.

Linux man Command Examples

The man command is a powerful tool for accessing documentation on system commands, programs, and libraries. It provides detailed information, including syntax, options, and examples, to help users understand how to use various commands effectively.

Below are some practical examples of how to use the man command to navigate and find the information you need.

Look for man Pages

The man command is used to view the manual pages for various system commands, programs, or files. It provides detailed documentation about a command's functionality, syntax, options, and usage.

When you run man followed by a command name, it opens the manual page associated with that command.

For example, to view the manual page for the sleep command, run:

man sleep
man sleep terminal output

Display man Pages and Print Short Descriptions

The -f option displays all man pages that match the specified command name, states the sections in which the given command is present, and prints out short descriptions.

Use the following syntax:

man -f [command name]

For example, for the sleep command, run:

man -f sleep
man -f sleep terminal output

The output lists results that match the search criteria. With multiple matches, the number next to the search result indicates the section.

Display man Pages From Specific Sections

To display the page from a specific section of a manual, use the syntax:

man [section number] [command name]

For example, to show the third section of the sleep command manual, run:

man 3 sleep
man 3 sleep terminal output

The output shows only the page from section three of the manual.

Display All man Pages

The -a attribute allows users to display all available intro manual pages contained in each section, one at a time.

man -a [command name]

For example, for the sleep command, run:

man -a sleep
man -a sleep terminal output

Quit between successive displays or skip through them using Ctrl+C or Ctrl+D, respectively.

Search by Considering Input as Regular Expression

The -k option allows users to search the short command descriptions and manual page names for a specified keyword as a regular expression. The output shows any available matches.

The syntax is:

man -k [keyword]

For example, to search for the keyword sleep, run:

man -k sleep
man -k sleep terminal output

Display Location of man Pages

The -w attribute shows the location of the manual page of the specified command. Adding the -a option prints out the locations of all files matching the keyword.

The syntax is:

man -wa [keyword]

For instance, for the sleep keyword, run:

man -wa sleep
man -wa-sleep terminal output

Alternative Ways to Access Manual Pages

Man pages are a traditional way to access detailed documentation for commands and programs in Linux. However, they are sometimes challenging to navigate.

To address this, several alternative methods provide simplified approaches to accessing command documentation. Some of these methods are:

  • tldr. Provides concise, simplified command explanations with practical examples.
  • apropos. Searches for keywords in man pages and displays matching commands with descriptions.
  • man2html. Converts man pages into HTML format, allowing for easier viewing in a web browser or GUI.
  • info. Displays detailed, hyperlinked documentation about commands, often more comprehensive than man pages.
  • whatis. Offers a one-line summary of a command's purpose.

Conclusion

This article explained how to use the man command in Linux. Use the command to see user manuals for Linux commands, search for a specific keyword, or see all the entries in the manual.

Next, learn about other Linux commands with our Linux commands cheat sheet.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Use the vmstat Command
March 18, 2021

The vmstat command is a Linux monitoring utility used to see various system statistics and to diagnose…
Read more
How to Use the usermod Command in Linux
March 4, 2021

The usermod command modifies user account details: username, password, home directory location, shell, and…
Read more
How to Use the who Command in Linux with Examples
February 25, 2021

The who command belongs to the GNU coreutils package in Linux. Its main purpose is to provide system…
Read more
How to Create a File in Linux Using Terminal/Command Line
July 11, 2024

Creating a file in Linux might seem straightforward, but there are some surprising and clever techniques. In…
Read more