Linux (2): Using the Linux Command Manual

1. Core Purpose & Concepts

  • Core Purpose:<span>man</span> (manual) command is the gateway to the built-in offline documentation system of Linux, addressing the core issue of “not having to remember every command’s usage and options,” providing you with an authoritative and quick reference source.
  • Core Terminology:
    • Man Page: An independent document page for a single command, configuration file, or programming interface. For example, <span>man ls</span> opens the manual page for the <span>ls</span> command.
    • Manual Section: The Linux manual is divided into 8 sections to categorize different types of topics for easier lookup and management.
    • <span>man</span> (command): A program used to search, locate, and display manual pages.
    • <span>help</span> (command): A command specifically used to display usage information for Shell built-in commands (Built-in), as these built-in commands do not have separate man pages.
    • <span>apropos</span> or <span>man -k</span>: Used to search for the names and descriptions of all man pages based on keywords, very useful when you do not know the exact command name.

2. Key Commands & Options

Basic Command Structure

Bash

man [section number] <command name>
# Search for all manual pages related to a keywordman -k "<keyword>"
# Get help for Shell built-in commandshelp <built-in command name>

Key Command Usage

Command / Option Function
<span>man <command name></span> Displays the manual page for a specific command (default starts searching from section 1).
<span>man <section number> <name></span> Precisely displays the manual page in the specified section. This is important for names that exist in multiple sections (e.g., <span>passwd</span>).
<span>man -k "keyword"</span> Searches for all manual pages with titles or descriptions containing “keyword”.
<span>help <built-in command></span> Displays help information for Shell built-in commands (e.g., <span>cd</span>, <span>echo</span>), which typically do not have a man page.
<span>q</span> (within man page) Exits (Quit) the current manual page and returns to the terminal.
<span>/</span> (within man page) Searches within the current manual page. Type <span>/</span> followed by the keyword, then press <span>Enter</span>. Use <span>n</span> to jump to the next match, and <span>N</span> to jump to the previous one.

Linux Manual Section Breakdown

This table serves as a map for quickly locating information. The sections most commonly used by beginners are 1, 5, and 8.

Section Content Description
1 User Commands Commands that ordinary users can execute in the Shell, usually without requiring administrative privileges.
2 System Calls Functions used in programming to request kernel services.
3 C Library Functions Function interfaces provided by the C programming library.
4 Devices and Special Files File system nodes representing hardware or software devices.
5 File Formats and Conventions Describes the structure and syntax of various configuration files (e.g., <span>/etc/passwd</span>).
6 Games Games available on the system.
7 Miscellaneous Overview of various topics such as protocols, file systems, etc.
8 System Administration Tools and Daemons Commands that require root or other administrative privileges to use (e.g., <span>useradd</span>).

Classic Command Examples

Bash

# Example 1: Read the manual page for the 'ls' command# Since ls is a user command (section 1), the section number can be omitted.man ls
# Example 2: I want to configure the system password policy but am unsure of the filename and format# Use man 5 passwd to view the file format description, not man 1 passwd (the command to change user passwords).man 5 passwd
# Example 3: I can't remember which command can "add users," let's search by keywordman -k "add user"# The output may include related commands like useradd (8), adduser (8), etc.
# Example 4: Try to view the manual page for 'cd' (will fail)man cd
# Output: No manual entry for cd
# This is because it is a Shell built-in command
# Example 5: Correctly get help for the 'cd' commandhelp cd

3. Practical Use Cases

  • Learning New Commands: When you first hear about the <span>rsync</span> command, <span>man rsync</span> is the best starting point to understand its functionality, syntax, and common options (e.g., <span>-a</span>, <span>-v</span>, <span>--delete</span>).
  • Confirming Command Options: You use <span>grep</span> every day, but suddenly forget how to perform a “case-insensitive” search. Running <span>man grep</span> and searching for <span>case</span> with <span>/</span> will quickly lead you to the <span>-i</span> (<span>--ignore-case</span>) option.
  • Understanding Configuration Files: Before editing critical system configuration files like <span>/etc/fstab</span>, it is essential to execute <span>man 5 fstab</span>. It will inform you of the meaning of each column, preventing system boot failures due to formatting errors.
  • Discovering Unknown Tools: When you want to “compress files” but do not know which command to use, <span>man -k "compress file"</span> will provide you with a list of tools, such as <span>gzip</span>, <span>zip</span>, <span>tar</span>, etc., giving you a reference.

4. Common Pitfalls

  • Using <span>man</span> on Built-in Commands: The most common mistake is executing <span>man</span> for Shell built-in commands like <span>cd</span>, <span>alias</span>, <span>export</span>, <span>echo</span>, etc. You will receive an error stating <span>No manual entry for...</span>.
    • Troubleshooting Tip: Upon seeing this error, your first reaction should be to try <span>help <command name></span>.
  • Confusing Search with Reading: Directly entering <span>man "some keyword"</span> is incorrect, as it will attempt to open a manual page named “some keyword”.
    • Troubleshooting Tip: Remember, use -k for searching, and directly follow the command name for reading.<span>man -k "keyword"</span> is the correct way to search.
  • Section Confusion: Names like <span>passwd</span> exist in both section 1 (commands) and section 5 (file formats). Directly executing <span>man passwd</span> will open the page from section 1. If you want to learn about the <span>/etc/passwd</span> file, you must explicitly specify the section number <span>man 5 passwd</span>.
  • Not Searching Within Pages: Manual pages can be very long. Scrolling through them is inefficient.
    • Troubleshooting Tip: Once inside a man page, immediately use <span>/</span> followed by your keyword to search, and use <span>n</span> and <span>N</span> to jump between matches. This can save a lot of time.

Leave a Comment