How to Read Manual Pages in Linux Using the man Command

Updated on August 16, 2024
 How to Read Manual Pages in Linux Using the man Command header image

Introduction

The man (manual) command is an important tool that provides detailed information about Linux commands and programs. It provides comprehensive documentation, including descriptions, options, usage examples, and related information about commands or a specific program.

This article explains how to use the man command in Linux to access and read manual pages.

man Command Syntax

Below is the basic man command syntax:

console
$ man [option] command_name

Within the above command, command_name sets the name of the command or program to view its manual page.

man Command Syntax

Option Description
-a Displays all manual pages for a specific command.
-k Search the short descriptions and manual page names for a specified keyword (equal to apropos).
-f Display the manual page titles for the specified command (equal to whatis).
-M Specifies a custom path to the manual pages.
-P Specifies a pager command other than the default.
-u Updates the database of manual pages.
-w Displays the location of the manual page files.

Practical Examples of the man Command

  1. Read the manual page of a specific command.

    console
    $ man ls
    

    The above command displays the manual page for the ls command, which includes detailed information about its usage.

    Output:

    man for special command

  2. Search for a command using a specific keyword in its description.

    console
    $ man -k copy
    

    The above command looks up a command's short description or manual page names with the keyword copy and lists all related commands.

    Output:

    command by keyword

  3. Display manual page titles.

    console
    $ man -f ls
    

    The above command displays the titles of manual pages for the ls command with a brief description for each.

    Output:

    page titles

  4. View all the manual pages for a specific command.

    console
    $ man -a intro
    

    The above command displays all manual pages for the intro command.

    Output:

    view all pages for command

  5. Display the location of manual page files.

    console
    $ man -w ls
    

    The above command outputs the path to the ls manual page.

    Output:

    location of page file

  6. Use man with a custom pager command.

    console
    $ man -P cat ls
    

    The above command uses cat instead of the default pager to display the ls manual page.

    Output:

    custom pager command

  7. Specify a manual page section to look up a specific command.

    console
    $ man 5 passwd
    

    The above command displays section 5 of the passwd manual page that includes the file format information.

    Output:

    specify section for command

Use the following keyboard shortcuts to navigate and search through the manual page contents.

  • Spacebar: Scroll down one screen at a time.
  • b: Scroll up one screen at a time.
  • Enter: Scroll down one line at a time.
  • k: Scroll up one line at a time.
  • /pattern: Search forward for a pattern.
  • ?pattern: Search backward for a pattern.
  • n: Repeat the last search in the same direction.
  • N: Repeat the last search in the opposite direction.
  • q: Quit the manual page viewer.

Understanding Manual Page Sections

Manual pages are divided into sections that include different types of information. Common sections include:

  • 1: User commands.
  • 2: System calls.
  • 3: Library functions.
  • 4: Special files (usually found in /dev).
  • 5: File formats and conventions.
  • 6: Games and screensavers.
  • 7: Miscellaneous.
  • 8: System administration commands.

Advanced Usage Scenarios

  1. View the manual pages for library functions.

    console
    $ man 3 printf
    

    The above command displays the manual page for the printf function, which is part of the C standard library.

    Output:

    view library function

  2. Read the manual pages for system calls.

    console
    $ man 2 open
    

    The above command displays the manual page for the open system call and provides information on how files are opened in the kernel.

    Output:

    view system call

  3. Use man in scripts to display specific documentation information about commands.

    • Create a new script file using a text editor such as Nano

      console
      $ nano my_script1.sh
      
    • Add the following contents to the file.

      bash
      #!/bin/bash
      echo "Displaying the manual page for the 'ls' command:"
      man ls
      
    • Enable execute permissions on the file.

      console
      $ chmod +x my_script1.sh
      
    • Run the script

      console
      $ ./my_script1.sh
      

    The above script displays the manual page for the ls command when executed.

    Output:

    script to display manual

  4. Combine the man command with grep to search pages.

    console
    $ man ls | grep "list"
    

    The above command pipes the manual page output for the ls command to grep and search for lines that contain the string list.

    Output:

    combine man with grep

  5. Update the manual pages database.

    console
    $ sudo mandb
    

    The above command updates the database of all manual pages to ensure new or removed pages are available in the search results.

Conclusion

You have used the man command to search for documentation and command usage pages. For more information about the man command, run man man to view the command's manual page.