# Cheat Sheet #day40 - man

## `man` Cheatsheet

### Basic Usage

* **Open the manual page for a command**
    
    ```bash
    man [command]
    ```
    
    Example:
    
    ```bash
    man ls
    ```
    

### Navigation

* **Move Down One Line**: `Down Arrow` or `j`
    
* **Move Up One Line**: `Up Arrow` or `k`
    
* **Move Down One Page**: `Space` or `Page Down`
    
* **Move Up One Page**: `b` or `Page Up`
    
* **Jump to the Beginning**: `g`
    
* **Jump to the End**: `G`
    
* **Move Forward One Word**: `w`
    
* **Move Backward One Word**: `b`
    

### Searching

* **Search Forward**: `/keyword`
    
* **Search Backward**: `?keyword`
    
* **Repeat Search Forward**: `n`
    
* **Repeat Search Backward**: `N`
    

### Exiting

* **Quit the Manual**: `q`
    

### Viewing Sections

Manual pages are divided into sections, such as:

1. User commands
    
2. System calls
    
3. Library functions
    
4. Special files (e.g., device files)
    
5. File formats and conventions
    
6. Games and screensavers
    
7. Miscellaneous
    
8. System administration commands
    

* **Specify a Section**: `man [section] [command]` Example:
    
    ```bash
    man 5 passwd
    ```
    

### Useful Options

* **Display the Manual Page for a Specific Section**
    
    ```bash
    man [section] [command]
    ```
    
    Example:
    
    ```bash
    man 3 printf
    ```
    
* **Show All Manual Pages Matching a Command**
    
    ```bash
    man -a [command]
    ```
    
    Example:
    
    ```bash
    man -a printf
    ```
    
* **View Help for** `man` Command
    
    ```bash
    man man
    ```
    
* **Print the Manual Page to STDOUT**
    
    ```bash
    man [command] | cat
    ```
    
    Example:
    
    ```bash
    man ls | cat
    ```
    
* **Specify Locale for Manual Pages**
    
    ```bash
    man --locale=[locale] [command]
    ```
    
    Example:
    
    ```bash
    man --locale=fr ls
    ```
    
* **Search for a Command Across All Sections**
    
    ```bash
    man -k [keyword]
    ```
    
    Example:
    
    ```bash
    man -k passwd
    ```
    
* **Format and Display the Manual Page in a Custom Way**
    
    ```bash
    man -P [pager_command] [command]
    ```
    
    Example:
    
    ```bash
    man -P cat ls
    ```
    
* **Display a Short Description of a Command**
    
    ```bash
    whatis [command]
    ```
    
    Example:
    
    ```bash
    whatis ls
    ```
    
* **Search Manual Page Names and Descriptions**
    
    ```bash
    apropos [keyword]
    ```
    
    Example:
    
    ```bash
    apropos network
    ```
    

### Combining `man` with Other Commands

* **Save a Manual Page to a File**
    
    ```bash
    man [command] > [filename]
    ```
    
    Example:
    
    ```bash
    man ls > ls_manual.txt
    ```
    
* **Print the Manual Page with** `col` to Remove Backspaces
    
    ```bash
    man [command] | col -b > [filename]
    ```
    
    Example:
    
    ```bash
    man ls | col -b > ls_manual.txt
    ```
    
* **Read a Compressed Manual Page**
    
    ```bash
    man -z [file]
    ```
    
    Example:
    
    ```bash
    man -z /usr/share/man/man1/ls.1.gz
    ```
    

### Additional Tips

* **Man Page Sections Order**: When you run `man [command]` without specifying a section, `man` searches through the sections in a predefined order. Typically, section 1 is searched first.
    
* **Customizing Pager**: You can customize the pager used by `man` with the `PAGER` environment variable. For example:
    
    ```bash
    export PAGER=less
    ```
    

This cheatsheet covers the essential commands and options for using the `man` command effectively, from basic navigation and searching to advanced usage and combining with other commands. Adjust the commands according to your specific requirements and environment.
