WCC logo

CIS120Linux Fundementals

Help and Man commands

In Linux, the help and man commands are essential tools for users to understand and utilize the vast array of commands and utilities available in the system. These commands provide detailed information and documentation, aiding both beginners and experienced users in mastering Linux commands.

The help Command

The help command is primarily used to display information about built-in shell commands. Since built-in commands are executed directly by the shell and not as separate programs, they often do not have separate manual pages. The help command provides a concise reference for these built-ins, explaining their usage and options.

To use the help command, simply type help followed by the name of the built-in command. For example:

help cd

This command will display information about the cd command, including its syntax and available options. The help command is specific to built-ins and will not work with external commands.

Common Options for the help Command

Option Description
-d Display a brief description of the command.
-m Display usage in a pseudo-manpage format.
-s Display a short usage synopsis for the command.
--help Display help information for the help command.

The man Command

The man (manual) command provides comprehensive documentation for a wide range of commands and programs in Linux. Each command or program typically has a manual page that describes its purpose, usage, options, and examples. The man pages are organized into sections, each covering a different category of commands or functions.

To use the man command, type man followed by the name of the command or program. For example:

man ls

This command will open the manual page for the ls command, which lists directory contents. The manual page includes a description of the command, its syntax, available options, and examples of how to use it.

Common Options for the man Command

Option Description
-k Search the short descriptions and manual page names for the keyword.
-f Display a one-line description of the command (equivalent to whatis).
-a Display all the manual pages for the command.
-w Print the location of the manual page files instead of displaying them.
--help Display a help message with available options.

Examples

Using help for a built-in command:

help echo

Output:

echo: echo [-neE] [arg ...]
    Write arguments to the standard output.
    
    Options:
      -n    do not append a newline
      -e    enable interpretation of backslash escapes
      -E    disable interpretation of backslash escapes (default)
    
    Exit Status:
    Returns success unless a write error occurs.

Using man for an external command:

man grep

Output:

GREP(1)                           User Commands                          GREP(1)

  NAME
         grep - print lines that match patterns
  
  SYNOPSIS
         grep [OPTION]... PATTERNS [FILE]...
         grep [OPTION]... -e PATTERNS ... [FILE]...
         grep [OPTION]... -f FILE ... [FILE]...
  
  DESCRIPTION
         grep searches for PATTERNS in each FILE.  A FILE of “-” stands for standard input.
         By default, grep prints the matching lines.
  
         In addition, three variant programs egrep, fgrep and rgrep are available:
         egrep is the same as ‘grep -E’.
         fgrep is the same as ‘grep -F’.
         rgrep is the same as ‘grep -r’.
  
  OPTIONS
         -i, --ignore-case
                Ignore case distinctions in patterns and input data.
  
         -v, --invert-match
                Select non-matching lines.
  
         -r, --recursive
                Read all files under each directory, recursively.
  
         -n, --line-number
                Prefix each line of output with the line number.
  
         -c, --count
                Suppress normal output; print a count of matching lines for each input file.
  
         -l, --files-with-matches
                Suppress normal output; print the name of each input file that contains a match.
  
         -w, --word-regexp
                Select only those lines containing matches that form whole words.
  
         -h, --no-filename
                Suppress the prefixing of file names on output.
  
         --help
                Display help and exit.
  
         --version
                Output version information and exit.
  
  EXAMPLES
         grep 'error' logfile
                Print all lines containing "error" in logfile.
  
         grep -i 'hello' file.txt
                Print lines containing "hello", case insensitive.
  
         grep -r 'TODO' ~/projects/
                Recursively search for "TODO" in all files under ~/projects/.
  
  SEE ALSO
         sed(1), awk(1), find(1), xargs(1)
  
  GNU Grep 3.7                        April 2023                            GREP(1)

Navigating the Man Pages

Within the man pages, you can navigate using the arrow keys to scroll up and down. Press q to quit and return to the command prompt.

Organization of man Pages

Man pages are organized into sections based on the type of command or documentation they contain. Here are the common sections:

Section Description
1 User commands (executable programs or shell commands).
2 System calls (functions provided by the kernel).
3 Library calls (functions within program libraries).
4 Special files (usually found in /dev).
5 File formats and conventions.
6 Games and screensavers.
7 Miscellaneous (macro packages, conventions, etc.).
8 System administration commands (usually only for root).

Accessing Specific Sections

If a command has entries in multiple sections, you can specify the section number. For example, to view the manual page for the passwd command related to user account management (section 1), use:

man 1 passwd