Table of Contents
Introduction
This guide will walk you through the ins and outs of using the man command in Linux, complete with examples, tips, and answers to common questions.
Linux is a versatile operating system that caters to users of all skill levels, from beginners to seasoned experts. One of its most powerful tools for understanding and utilizing commands effectively is the man
command. Short for “manual,” the man
command provides comprehensive documentation for nearly every tool and command in Linux. Whether you’re troubleshooting, exploring new commands, or fine-tuning your workflow, mastering the man
command is essential.
What Is the man
Command?
The man
command is a built-in tool in Linux that displays the manual pages (man pages) for other commands and utilities. It serves as a comprehensive reference, offering detailed information about a command’s syntax, options, and examples.
Key Features of the man Command:
- Provides detailed documentation for commands and utilities.
- Offers multiple sections, covering user commands, system calls, configuration files, and more.
- Helps users understand command usage, options, and examples.
How to Use the man Command
Basic Syntax
The basic syntax for the man
command is:
man [-acdfFhkKtwW] [–path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S section_list] [section] name …
On the man page, the describes it
- format and display the on-line manual pages.
man man – More details information about man command.
man command in Linux with Examples
$ man man
$ man free
Examples of Basic Usage
Viewing a Manual Page
To view the manual page for a command like ls
, run:
man ls
Once inside a manual page:
- Use the arrow keys to scroll up and down.
- Press
q
to quit the manual page. - Press
/
followed by a search term to find specific text.
Viewing a Specific Section
Linux manual pages are divided into numbered sections. For example, to view the manual page for the open
system call in section 2:
man 2 open
Manual Page Sections Explained
Linux man pages are divided into sections based on their content. Here are the most commonly used sections:
- User Commands: Regular commands for daily use.
- System Calls: Functions provided by the kernel.
- Library Functions: Standard programming functions.
- Special Files: Device files and drivers.
- File Formats and Conventions: Configuration files and syntax.
- Games and Screensavers: User-related entertainment tools.
- Miscellaneous: Other topics, including macro packages.
- System Administration Commands: Commands for system maintenance.
Advanced Usage of the man Command
Searching for Keywords
If you’re unsure which command to use, search by keyword with the -k
option:
man -k "keyword"
For example, to find all commands related to “disk”:
man -k disk
Viewing All Sections of a Command
Sometimes, a command has entries in multiple sections. Use the -a
option to view all related sections:
man -a open
Printing a Manual Page
To print or save a manual page, use the -t
option:
man -t ls | lpr
Customizing man
Output
Change the default pager for man
pages by setting the PAGER
environment variable:
export PAGER=less
Examples of the man Command in Action
Example 1: Understanding the grep
Command
To learn about grep
, a powerful text-searching tool:
man grep
The manual explains:
- How to search for patterns in files.
- Options like
-i
for case-insensitive searches.
Example 2: Debugging with strace
To explore how to use strace
for debugging:
man strace
Learn to trace system calls and signals of a process.
Example 3: Creating Custom Scripts
Check the manual for bash
to build robust shell scripts:
man bash
Frequently Asked Questions About the man Command
1. What if the man
command is not found?
Ensure the man
package is installed. On Debian-based systems, use:
sudo apt install man-db
2. How do I find the version of a command?
The man
command does not directly show versions. Use the --version
option of the command, e.g., ls --version
.
3. Can I view man pages online?
Yes, many Linux distributions provide online manuals, such as man7.org.
4. How do I search within a man page?
Use /
followed by your search term, then press Enter. Navigate through matches using n
for next and N
for previous.
5. How do I access man pages for a specific program installed manually?
Update the MANPATH
environment variable to include the directory of the manual pages.
External Links
Conclusion
man