Table of Contents
Using Built‑In Help in the Shell
On Linux, you almost never have to guess how a command works. The system provides several layers of help that you can access directly from the terminal.
This chapter focuses on practical ways to find and understand help for commands while working in a shell.
`--help` and `-h` Options
Many commands can show a brief usage summary directly:
command --helpcommand -h(not universal, but common)
Examples:
ls --help
grep --help
tar -h
ip --helpTypical things you’ll see:
- Command syntax: which arguments go where
- Common options and a short description
- Version information (sometimes with
--version)
Use this when:
- You need a quick reminder of options
- You don’t want to leave the terminal or scroll a long manual
Remember: --help is not guaranteed, but it’s widely supported for most modern tools.
The `man` Pages (Manual Pages)
The main source of detailed documentation on Linux is the man command (“manual”).
Basic Usage
man commandExamples:
man ls
man cp
man passwdYou can also view specific sections (details below):
man 5 passwdNavigating `man` Pages
Inside a man page:
- Move:
- Arrow keys or
j/k: line by line Space: next pageb: previous pageg: go to startG: go to end- Search:
/textthen Enter: search forward fortextn: next matchN: previous match- Quit:
q: exit the man page
These key bindings come from the less pager, which man uses under the hood.
`man` Page Sections
The manual is divided into numbered sections. Common ones:
- User commands (programs you run in the shell)
- System calls (kernel-level functions, for programmers)
- Library calls (C library functions)
- Special files (e.g. in
/dev) - File formats and conventions (e.g. config file formats)
- Miscellaneous (conventions, standards)
- System administration commands
You may see references like:
printf(1)→ user commandprintf(3)→ C library function
To choose a section:
man 1 printf
man 3 printfTo see which pages exist for a name:
man -f printfSearching the Manual: `man -k` and `apropos`
If you don’t know the exact command name, you can search by keyword.
`man -k` and `apropos`
man -k and apropos are essentially the same:
man -k keyword
apropos keywordExamples:
man -k copy
man -k user
apropos network
This searches the NAME and short description fields of all man pages.
If you get no results, you may need to update the index (requires root):
sudo mandbGetting Help for Built‑In Shell Commands: `help`
Some commands are built into the shell itself (e.g. Bash) and don’t have normal man pages.
Use the shell’s help for these:
help
help builtin_nameExamples (in Bash):
help cd
help echo
help read
help ifThis shows:
- Usage of the built‑in
- Shell‑specific behavior
- Brief description
To find out if something is a built‑in or external program, use type:
type cd
type lsGetting Bash Manual: `man bash` and `info bash`
Bash has a very large manual:
man bashUseful while learning:
- Shell syntax
- Conditionals, loops, and other scripting basics
- Built‑in commands and variables
For a more structured manual with sections and cross‑links, you can also use:
info bashThe `info` System
Some programs use GNU info documentation, which is more hypertext-style than man pages.
Basic usage:
info programExamples:
info coreutils
info ls
info grep
Inside info:
- Arrow keys: move
Space: next screenb: previous screenTab: jump between linksEnter: follow a linku: go up one levelq: quit
In practice, most beginners use man and --help more often than info, but it’s useful for some GNU tools with detailed manuals.
Quick File Viewing: `whatis` and `man -f`
To get a one‑line description of a command:
whatis commandman -f command(same effect)
Examples:
whatis ls
man -f passwdYou’ll see entries like:
ls (1) - list directory contents
passwd (1) - change user password
passwd (5) - password fileDiscovering Commands by Name: `compgen` and TAB Completion
Many shells can help you discover commands:
Listing Available Commands Starting with Letters
In Bash:
compgen -c ls
compgen -c git
This lists all commands starting with ls or git. Not something you’ll use constantly, but handy when exploring.
Using TAB for Hints
While typing:
- Type part of a command and press
Tab: - If unique: it auto‑completes.
- If multiple: press
Tabtwice to see choices.
Example:
- Type
grethenTab→ often expands togrep(if unambiguous).
Online Help from the Shell (Manual Pages on the Web)
You can view man pages in a browser if you prefer:
https://man7.org/linux/man-pages/https://manpages.debian.org/https://linux.die.net/man/
From the shell, you can quickly copy command names from these sites, but using local man pages is usually faster and works without internet.
Common Problems and Tips
“No manual entry for …”
If man says there is no manual entry:
- Check if the command exists:
which command
type command- The command might be:
- A shell built‑in → use
help command - A function or alias → see
type command - Installed without man pages (common for some third‑party tools)
When to Use What
- Need a quick reminder of options:
command --help- Need detailed explanation:
man command- Don’t know the command name:
man -k keywordorapropos keyword- Dealing with a shell built‑in:
help name(and optionallyman bashfor full details)- Want more structured, hyperlinked docs (mostly GNU tools):
info command
Practice Suggestions
Try these to build the habit of using help:
- For three commands you already know (e.g.
ls,cp,grep): - Run
command --help - Then run
man command - Find one option you didn’t know before and test it.
- Use
man -kto find commands related to: usernetworktime- In Bash:
- Run
type cd, thenhelp cd - Compare that with
man cd(you’ll likely getman 1 bashor nothing, illustrating the difference).