The man command in Linux: command reference manual

Introduction

In the world of Linux, the terminal is the gateway to the system’s power. One of the most valuable tools every user should know is the man command, short for manual. This command allows you to access the built-in documentation for almost any utility, program, or system call, providing a quick and detailed reference without needing to search the web.

What is the man command?

The man command displays manual pages, which are organized into numbered sections. Each section groups a type of documentation: for example, section 1 contains user commands, section 2 system calls, section 3 C library functions, and so on. Invoking man followed by the name of a command causes the system to locate the corresponding page and display it in a text viewer, normally less, which allows navigation with arrow keys, page up/down, and exiting with q.

Basic Syntax

The simplest way to use man is:

man command

Where command is the name of the program whose manual you wish to consult. If you don’t know the exact name, you can search with the -k option (or apropos) which searches the descriptions in the manual pages:

man -k keyword

This returns a list of pages that contain the keyword in their brief description.

Navigating within a manual page

Once the page is open, you can:

  • Move line by line with the ↑ and ↓ arrow keys.
  • Advance or retreat a full page with Space and b.
  • Go directly to the end with G or to the beginning with g.
  • Search for a pattern by typing /pattern and pressing Enter; repeat the search with n (next) or N (previous).
  • Exit the viewer with q.

Practical Examples

Consult the manual for the ls command to list directories:

man ls

If you want to know how to use the -l option of ls, search within the page:

/ -l

To see all options related to compression, you can consult the manual for gzip and search for the word compress:

man gzip
/compress

Another utility is to check which section a command belongs to. For example, man 2 open displays the page for the system call open (section 2), while man 3 printf shows the C library function printf (section 3).

Customizing the display

The default viewer is usually less, but you can change it by defining the environment variable MANPAGER. For example, to use vim as the viewer:

export MANPAGER="vim -M +MANPAGER -"
man ls

You can also adjust the output width with the variable MANWIDTH; setting it to 80 ensures that lines do not break unexpectedly in narrow terminals.

Tips and best practices

  • When you don’t remember the exact name of a command, use apropos or man -k to explore.
  • If a manual page is very long, save its content to a file for later reading: man command > command.txt.
  • In modern distributions, manual pages may be available in multiple languages; specify the language with the LANG or LC_MESSAGES variable.
  • To update the manual page database (useful after installing new software), run mandb as root.
  • Remember that some programs include their own documentation in info format or via --help; man is just one of the available sources.

Conclusion

Mastering the man command is essential for any Linux user or administrator. It provides immediate access to official documentation, reduces reliance on external searches, and enables structured and efficient learning. The next time you need to know how an option works or the purpose of a command, open your terminal, type man, and let the manual guide you.

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .