Using man Pages and Command Help

Su Suriya Ravichandran Updated 06 Dec 2026
8 min read ·Lesson 23 of 205

No one remembers every option of every command. What separates a confident Bash user from a beginner is knowing where to look. Linux and Bash include their own documentation, available offline in your terminal, and most questions can be answered in seconds without a web search. This lesson shows the four sources you will use most: help for Bash built-ins, --help for most other commands, man pages for the full manual, and type to find out what kind of command you are dealing with.

Understanding the Concept

Commands come from two places (the earlier lesson on built-in and external commands explained the difference), and each place documents itself differently:

Kind of commandWhere its documentation livesHow to read it
Bash built-in, such as cd or pwdInside Bash itselfhelp cd
External program, such as ls or grepThe program and its manual pagels --help or man ls
Shell keyword, such as if or forInside Bash itselfhelp if

So the first question is always: what kind of command is this? The type command answers it.

Finding Out What a Command Is

The -t option of type prints one word describing the command:

type -t cd ls if

Output:

builtin
file
keyword

The word builtin means the command is part of Bash, file means it is a separate program on disk, and keyword means it is part of the shell's syntax. Without -t, type gives a longer answer:

type -a ls

Output (the paths depend on your system):

ls is /usr/bin/ls
ls is /bin/ls

The option -a lists every place where the name is found. A built-in command is documented by help, so when type -t says builtin or keyword, use help.

Help for Built-in Commands

The help command is itself a built-in. Given a command name, it prints that command's usage and a description. This is the beginning of the output for cd:

help cd

Output (first lines):

cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable. If DIR is "-", it is converted to $OLDPWD.
    
    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).

The first line is the synopsis: the command followed by the options it accepts. In a synopsis, square brackets mean the part is optional, and a vertical bar separates alternatives. Here [-L|[-P [-e]] [-@]] says the options are all optional and that -L and -P are alternatives.

Three options of help give shorter or longer views:

help -d pwd
help -s pwd
help -m pwd

Output of the first two:

pwd - Print the name of the current working directory.
pwd: pwd [-LP]

The option -d prints a one-line description and -s prints only the synopsis. The option -m prints the full text in a manual-page layout, beginning with NAME, SYNOPSIS and DESCRIPTION sections. The command help help describes help itself, and plain help with no argument lists every built-in.

Shell keywords are documented the same way. Run help if or help for to see the syntax of those statements.

To see how many built-ins your Bash has, use compgen:

compgen -b | wc -l

Output (the count depends on the Bash version; Bash 5.2 printed this number):

61

Help for External Commands

Most external commands support a --help option that prints a short usage message. It is the quickest way to refresh your memory about an option name:

ls --help | head -6

Output:

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .

The | head -6 part keeps only the first six lines, because the full text is long. For longer help you can send the output to a pager: ls --help | less.

--help is a convention, not a rule. GNU tools such as ls and grep support it, and the same goes for many modern programs, but some commands use -h, -?, or help as a subcommand. Programs also commonly offer --version to print their version:

ls --version | head -1

Output:

ls (GNU coreutils) 9.4

If you give a command an option it does not know, it normally explains the mistake and points to its help:

ls --nosuchoption
echo "status=$?"

Output:

ls: unrecognized option '--nosuchoption'
Try 'ls --help' for more information.
status=2

The exit status 2 signals a usage error. The message is a useful hint: it tells you the exact command that will show the correct options.

Reading Manual Pages with man

A manual page, or man page, is the complete reference for a command. It is longer than --help and includes every option, explanations, examples, exit codes and related commands. Open one by giving man the name of the command:

man ls

The page opens in a pager, a program that shows a long text one screen at a time. On most systems the pager is less. The page does not print and exit; it stays open until you press q.

Note: some minimal systems, such as containers and cloud images, ship man without the manual pages themselves, and then man ls prints a message saying the system has been minimized. On a normal desktop or server install, the pages are present. If they are missing on yours, installing the package named man-db and the packages with the manual pages (on Ubuntu, manpages) restores them.

Moving Around a Page

Because the pager is less, you can use its keys:

KeyAction
Space or fScroll forward one screen
bScroll back one screen
↓ / ↑Scroll one line
/text then EnterSearch forward for text
nJump to the next search match
NJump to the previous search match
gGo to the top
GGo to the bottom
hShow the pager's own help
qQuit

Searching is the key skill. If you want to know how to sort ls output by size, open the page, type /size, press Enter, and press n until you reach the option you want.

How a Page Is Organized

Man pages follow a standard layout. You will almost always see these headings:

SectionWhat it contains
NAMEThe command and a one-line description
SYNOPSISThe exact syntax, using the same bracket notation as help
DESCRIPTIONWhat the command does, and usually the list of options
OPTIONSThe options, if they are separate from the description
EXIT STATUSThe meaning of each exit code
EXAMPLESSample uses (not every page has this)
SEE ALSORelated commands and pages

When reading a synopsis, remember the notation: text in square brackets is optional, an ellipsis (...) means the item can repeat, and a vertical bar separates choices. The synopsis ls [OPTION]... [FILE]... means that ls takes any number of options and any number of files, all optional.

Manual Sections

The manual is divided into numbered sections, and the same name can appear in more than one:

SectionContents
1User commands and programs
2System calls
3Library functions
5File formats and configuration files
7Overviews and conventions
8System administration commands

The section number is written in parentheses after the name, as in ls(1). When two pages share a name, you choose one by putting the section first. For example, man 5 passwd opens the description of the /etc/passwd file, while man passwd opens the command that changes a password.

Searching When You Do Not Know the Name

Sometimes you know what you want to do but not which command does it. Two tools search the short descriptions of all man pages:

man -k "copy files"
apropos "copy files"

Both search the one-line descriptions and list the pages that match, each with its section number. The command whatis works the opposite way: given a command name, it prints its one-line description.

whatis ls

These tools depend on a prebuilt index that the system updates regularly. On a freshly installed system the index may be empty, and the search prints nothing until it is built.

Other Sources of Help

Some programs have richer documentation than a man page. The GNU project documents many tools in the info format, read with info coreutils. Bash also has a complete reference manual, which you can open with man bash. It is long, so use the search key. For example, open it and type /Parameter Expansion to find that section.

Many commands also ship examples in the directory /usr/share/doc. And the first step when a command gives an error is often the simplest one: read the message. As the ls example showed, many programs tell you exactly how to get more help.

Practical Applications

Checking what an unfamiliar command does before you run it:

whatis rsync

Finding the option that makes grep count matches, without leaving the terminal:

man grep

Then type /count, press Enter, and read the entry for -c.

Confirming that a command is available in a script before it is used:

type -t grep

If the command does not exist, type -t prints nothing and returns a non-zero exit status, so a script can test it. The later lessons on functions and error handling use this idea.

Picking the right help tool in a single line: use help when type -t says builtin or keyword, use --help for a quick reminder, and use man for the complete explanation.

0 Comments

Reviewed before they appear

No comments yet.

Bash
Introduction to Bash What Is a Shell? What Is Bash (Bourne Again Shell)? Bash vs. Shell vs. Terminal Bash vs. sh, Zsh, and Fish Where Bash Is Used: Linux, DevOps, and Automation Installing Bash on Linux Using Bash on macOS Using Bash on Windows with WSL Checking Your Bash Version Opening and Using a Terminal Running Your First Bash Command Understanding Command Syntax and Arguments Bash Built-in Commands vs. External Commands Working with pwd, ls, and cd Creating Files and Directories with touch and mkdir Copying, Moving, and Renaming Files Removing Files and Directories Safely Viewing Files with cat, less, head, and tail Searching for Files with find Searching Text with grep Understanding File Paths and Wildcards Using man Pages and Command Help Bash Script Structure Creating Your First Bash Script Understanding the Shebang (#!/usr/bin/env bash) Making a Script Executable with chmod Running a Bash Script in Different Ways Writing Comments in Bash Using echo and printf Reading User Input with read Displaying Helpful Messages in Scripts Using Semicolons and Newlines Bash Variables: Declaration and Usage Rules for Naming Bash Variables Environment Variables Local Variables vs. Environment Variables Exporting Variables with export Common Environment Variables: HOME, PATH, USER, and PWD Read-Only Variables with readonly Removing Variables with unset Command-Line Arguments: $0, $1, and More Special Parameters: $#, $?, $$, $!, $@, and $* Positional Parameters and shift Default Values with Parameter Expansion Single Quotes vs. Double Quotes Escaping Special Characters Command Substitution with $(...) Arithmetic Expansion with $((...)) Brace Expansion Tilde Expansion and Home Directories Filename Expansion and Globbing Understanding Word Splitting Parameter Expansion Basics Why Quoting Variables Matters Standard Input, Standard Output, and Standard Error Redirecting Output with > and >> Redirecting Input with < Redirecting Errors with 2> Combining Standard Output and Standard Error Using Pipes (|) to Connect Commands Using tee to Save and Display Output Here Documents with << Here Strings with <<< Command Lists with ;, &&, and || Conditional Statements with if, then, and fi Using elif and else Testing Conditions with test and [ ] Using [[ ]] for Bash Conditionals Comparing Strings in Bash Checking Whether Files Exist Checking File Types and Permissions Integer Comparisons in Bash Logical Operators: &&, ||, and ! Using case Statements Pattern Matching in case Common Conditional Statement Mistakes for Loops in Bash C-Style for Loops while Loops until Loops Looping Through Files and Directories Looping Through Command Output Safely break and continue Nested Loops select Loops for Simple Menus Avoiding Infinite Loops Defining and Calling Bash Functions Passing Arguments to Functions Returning Status Codes from Functions Understanding return vs. echo in Functions Local Variables in Functions Function Scope and Variable Visibility Organizing Scripts into Functions Sourcing Other Bash Files with source Reusable Bash Utility Functions Indexed Arrays in Bash Creating and Accessing Array Elements Adding and Removing Array Elements Looping Through Arrays Array Length and Indices Associative Arrays in Bash Iterating Over Associative Arrays Passing Arrays to Functions Common Array Pitfalls Processing Text with grep, sed, and awk Using cut, sort, uniq, and wc Finding and Replacing Text with sed Extracting Columns with awk Parsing CSV-Like Text from the Command Line Working with Filenames That Contain Spaces Safe File Handling with find -print0 and xargs -0 Temporary Files with mktemp Reading Files Line by Line Appending Logs to a File Understanding Exit Codes Checking Command Success with $? Using exit to End a Script Fail-Fast Scripts with set -e: Benefits and Caveats Using set -u and set -o pipefail Combining Strict Mode Options Safely Handling Errors with if Statements Traps with trap Cleaning Up Temporary Files on Exit Writing Useful Error Messages Debugging Scripts with bash -x Parsing Script Arguments Validating Required Arguments Handling Optional Arguments Parsing Options with getopts Building Help Messages with --help Setting Defaults for Optional Parameters Handling Unknown Options and Invalid Input Creating Interactive Menus in Bash Foreground and Background Processes Running Commands in the Background with & Managing Jobs with jobs, fg, and bg Waiting for Processes with wait Capturing Process IDs with $! and $$ Sending Signals with kill Handling Interrupts and Termination Signals Running Commands with timeout Basic Process Monitoring from Bash Aliases and Shell Functions: When to Use Each Customizing the Bash Prompt (PS1) Bash Startup Files: .bashrc, .bash_profile, and Profile Interactive vs. Non-Interactive Bash Shell Options with set shopt: Enabling Bash-Specific Options Directory Stack with pushd, popd, and dirs Process Substitution with <(...) and >(...) Advanced Parameter Expansion Pattern Matching and Extended Globbing Bash Script Security Fundamentals Avoiding Command Injection in Shell Scripts Quoting User Input Safely Why eval Is Risky and Safer Alternatives Handling Secrets and Credentials in Scripts Using Least Privilege in Automation Scripts Safe Use of rm and Destructive Commands Validating Paths and User-Supplied Filenames ShellCheck: Static Analysis for Bash Scripts Writing Readable and Maintainable Bash Automating Backups with Bash Creating Log Rotation and Cleanup Scripts Checking Disk Usage and Free Space Monitoring CPU, Memory, and System Load Checking Website Availability with curl Automating Updates on Ubuntu and Debian Scheduling Bash Scripts with cron Using Lock Files to Prevent Duplicate Runs Building a Simple Health-Check Script Sending Notifications from Bash Scripts Using Bash in Git Workflows Bash Scripts for Docker Automation Automating Docker Container Health Checks Using Bash in CI/CD Pipelines Environment Configuration for Deployment Scripts Automating SSH Tasks with Bash Deploying a Web Application with a Bash Script Using Bash to Process Application Logs Building Repeatable Development Setup Scripts Bash Debugging Techniques Using set -x and PS4 for Debug Traces Testing Bash Scripts with Bats Mocking Commands During Script Tests Testing Error Paths and Exit Codes Writing Portable Shell Scripts Bash-Specific Syntax vs. POSIX Shell Syntax Using ShellCheck in a Development Workflow Performance Tips for Bash Scripts Build an Interactive Calculator Build a File and Directory Organizer Build a Timestamped Backup Script Build a Log File Analyzer Build a Bulk File Renaming Tool Build a System Resource Monitoring Script Build a Website Uptime Checker Build a User Account Audit Report Build a Database Backup Automation Script Build a Docker Cleanup Helper Build a Server Health-Check and Alert Script Build a Deployment Automation Script Build a Menu-Driven Linux Administration Toolkit Build a Safe Automated Backup and Restore Workflow
Ask about this post
AI Ask about this post

Ask questions about Using man Pages and Command Help and get answers drawn from it.

Signed-in readers only.