Chapter 29: Linux Man Pages

Man pages, short for manual pages, are the built-in documentation system for Linux and Unix-like operating systems. They provide detailed information about commands, system calls, library functions, configuration files, and other aspects of the operating system. Think of them as the “help manual” for Linux, available right at your fingertips in the terminal.

Relevance and Importance

Man pages are an essential resource for anyone working with Linux, whether you’re a beginner or an experienced user. Here’s why they matter: 
1. Comprehensive Documentation: Man pages provide in-depth explanations of commands, including their syntax, options, and usage examples. 
2. Always Available: They are pre-installed on almost all Linux distributions, so you don’t need an internet connection to access them. 
3. Standardized Format: Man pages follow a consistent structure, making it easy to find the information you need. 
4. Learning Tool: They are a great way to explore new commands and understand how they work.

Languages Available

Man pages are primarily written in English, but translations are available in other languages for many commands. To check if a man page is available in your preferred language, you can set the LANG environment variable. For example:

$ LANG=es man ls  # Displays the man page for 'ls' in Spanish 

How to Effectively Use Man Pages

Here are some tips to make the most of man pages as a reference:

  1. Accessing Man Pages:
  2. To view a man page, use the man command followed by the name of the command or topic. For example: 
    $ man ls

This will display the manual page for the lscommand.

Navigating Man Pages:

  1. Use the arrow keys to scroll up and down.
  2. Press Spacebar to move forward one page or B to move backward.
  3. Use / followed by a search term to find specific text (e.g., /option to search for “option”).

Press Q to quit and return to the terminal.

Understanding the Structure: Man pages are divided into sections, each providing specific information:

  1. NAME: The name of the command and a brief description.
  2. SYNOPSIS: The command syntax, including options and arguments.
  3. DESCRIPTION: A detailed explanation of the command and its functionality.
  4. OPTIONS: A list of available options and what they do.
  5. EXAMPLES: Practical examples of how to use the command.

Searching for Man Pages:

  1. If you’re unsure which command to use, you can search the man page database using the -koption:
    $ man -k keyword # Searches for man pages containing "keyword"

For example: 
 $ man -k "list files"

Viewing Specific Sections: Man pages are organized into numbered sections (e.g., 1 for user commands, 2 for system calls). To view a specific section, specify the section number before the command name:
$ man 2 open # Displays the $ man page for the 'open' system call

Printing Man Pages:

To print a man page, use the -t option to format it for printing and pipe it to a printer command:

$ man -t ls | lpr # Prints the man page for 'ls'

Customizing Man Page Display:

You can customize the appearance of man pages by setting environment variables like PAGER or MANPAGER. For example:
$ export PAGER="less -R" # Enables colored output in man pages


Modern Alternatives to man Pages:

man pages are the traditional way to access documentation for Linux commands and utilities. They are thorough but can be a bit overwhelming for new users. Here are some alternatives that offer a more user-friendly experience:

tldr (Too Long; Didn’t Read):

  • What it is: tldr is a community-driven project that provides simplified and practical examples of how to use commands. It focuses on the most common use cases, avoiding the verbosity of man pages.
  • Pros:
    • Very concise and easy to understand.
    • Great for quick lookups and common use cases.
    • Cross-platform support.
  • Cons:
    • Does not cover all options and features as thoroughly as man pages.
  • How to install: Usually available through your package manager. 
    $ sudo apt install tldr # Debian/Ubuntu 
    $ sudo pacman -S tldr # Arch/Manjaro
  • How to use: $ tldr <command> # E.g., tldr tar

navi:

  • What it is: navi is an interactive command-line tool that allows you to browse cheat sheets and execute commands. It’s like having a searchable and executable tldr inside your terminal.
  • Pros:
    • Searchable cheatsheets and the ability to execute them directly.
    • Supports custom cheatsheets and community contributions.
    • Interactive and flexible.
  • Cons:
    • Requires a bit of initial setup.
  • How to install: Usually available through your package manager, or you can check their Github. $ sudo apt install navi # Debian/Ubuntu
  • How to use: 
    $ navi # runs navi on interactive mode navi <command> # e.g. $ navi tar

cheat:

  • What it is: cheat is similar to tldr but allows you to create and share your own cheat sheets. It’s great for commands you use frequently or have customized.
  • Pros:
    • Simple and customizable cheat sheets.
    • Easy to create your own command examples.
  • Cons:
    • May require more effort to setup than tldr.
  • How to install: Usually available through your package manager: 
    $ sudo apt install cheat # Debian/Ubuntu
  • How to use: # cheat <command> # E.g., cheat git

While traditional man pages can be overwhelming, modern documentation tools like tldr and cheat.sh provide simplified, example-focused references for common commands. 

For personal scripts, creating custom man pages ensures easy access to documentation. By utilizing these modern documentation resources, you can quickly find the information you need, making command-line usage more efficient and less daunting for beginners.

$ tldr ls

Which Alternative to Choose:

  • For quick command help and examples: tldr or cheat are good.
  • For an interactive command cheatsheet: navi is great
  • For thorough documentation: the traditional man pages.

Conclusion

Man pages are an indispensable tool for Linux users, offering a wealth of information directly from the command line. By learning how to navigate and use them effectively, you can quickly find answers to your questions, discover new commands, and deepen your understanding of the Linux operating system. Whether you’re troubleshooting, learning, or exploring, man pages are your go-to reference guide.


Prev: Chapter 28 | Next: Chapter 30