Kahibaro
Discord Login Register

2.1.5 Getting help

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:

Examples:

ls --help
grep --help
tar -h
ip --help

Typical things you’ll see:

Use this when:

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 command

Examples:

man ls
man cp
man passwd

You can also view specific sections (details below):

man 5 passwd

Navigating `man` Pages

Inside a 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:

  1. User commands (programs you run in the shell)
  2. System calls (kernel-level functions, for programmers)
  3. Library calls (C library functions)
  4. Special files (e.g. in /dev)
  5. File formats and conventions (e.g. config file formats)
  6. Miscellaneous (conventions, standards)
  7. System administration commands

You may see references like:

To choose a section:

man 1 printf
man 3 printf

To see which pages exist for a name:

man -f printf

Searching 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 keyword

Examples:

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 mandb

Getting 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_name

Examples (in Bash):

help cd
help echo
help read
help if

This shows:

To find out if something is a built‑in or external program, use type:

type cd
type ls

Getting Bash Manual: `man bash` and `info bash`

Bash has a very large manual:

man bash

Useful while learning:

For a more structured manual with sections and cross‑links, you can also use:

info bash

The `info` System

Some programs use GNU info documentation, which is more hypertext-style than man pages.

Basic usage:

info program

Examples:

info coreutils
info ls
info grep

Inside info:

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:

Examples:

whatis ls
man -f passwd

You’ll see entries like:

ls (1)  - list directory contents
passwd (1) - change user password
passwd (5) - password file

Discovering 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:

Example:

Online Help from the Shell (Manual Pages on the Web)

You can view man pages in a browser if you prefer:

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:

  which command
  type command

When to Use What

Practice Suggestions

Try these to build the habit of using help:

  1. 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.
  2. Use man -k to find commands related to:
    • user
    • network
    • time
  3. In Bash:
    • Run type cd, then help cd
    • Compare that with man cd (you’ll likely get man 1 bash or nothing, illustrating the difference).

Views: 75

Comments

Please login to add a comment.

Don't have an account? Register now!