Command line help and documentation
This lesson will cover how to use built-in help commands and command documentation. You will discover how to qucikly access help pages to learn about a command, or refresh your knowledge of how to use it.
Built-in Help Systems
The help command
The help command is used to list all availble commands, or find out about a specific command:
# Show all available commands
help
# Get help for a specific command
help command_name
Output:
C:\Users\name>help
For more information on a specific command, type HELP command-name
ASSOC Displays or modifies file extension associations.
ATTRIB Displays or changes file attributes.
BREAK Sets or clears extended CTRL+C checking.
BCDEDIT Sets properties in boot database to control boot loading.
CACLS Displays or modifies access control lists (ACLs) of files.
CALL Calls one batch program from another.
CD Displays the name of or changes the current directory.
...
The man command (command manual)
# View manual page for a command
man command_name
# Search manual pages
man -k search_term
Here is the shortened result of man mkdir:
MKDIR(1) General Commands Manual MKDIR(1)
NAME
mkdir – make directories
SYNOPSIS
mkdir [-pv] [-m mode] directory_name ...
DESCRIPTION
The mkdir utility creates the directories named as operands, in the order
specified, using mode “rwxrwxrwx” (0777) as modified by the current
umask(2).
The options are as follows:
-m mode Set the file permission bits of the final created directory
to the specified mode. The mode argument can be in any of
the formats specified to the chmod(1) command. If a
symbolic mode is specified, the operation characters ‘+’
and ‘-’ are interpreted relative to an initial mode of
“a=rwx”.
-p Create intermediate directories as required. If this
option is not specified, the full path prefix of each
operand must already exist.
...
💡 Tip: Use the
qkey to exit the manual.
Understanding the command manual
Manual sections
As you will see in the above example, the man command is broken down into sections such as:
- NAME: Command name and brief example.
- SYNOPSIS: The syntax and options.
- DESCRIPTION: Detailed description.
- OPTIONS: Available command options.
- EXIT STATUS: Exit status values returned..
- EXAMPLES: How to use.
- SEE ALSO: Related commands.
- HISTORY: Command history and versions.
Navigating the manual
- Space: Next page.
b: Previous pagee: Scroll down by one line.y: Scroll down by one line.z: Forward by one window.w: Backward by one window./: Search (/term_to_search)q: Quit/exit.
While viewing the manual, you can also use h to list a full range of keyboard commands:
Commands marked with * may be preceded by a number, N.
Notes in parentheses indicate the behavior if N is given.
A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.
h H Display this help.
q :q Q :Q ZZ Exit.
---------------------------------------------------------------------------
MOVING
e ^E j ^N CR * Forward one line (or N lines).
y ^Y k ^K ^P * Backward one line (or N lines).
f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v * Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).
ESC-SPACE * Forward one window, but don't stop at end-of-file.
d ^D * Forward one half-window (and set half-window to N).
u ^U * Backward one half-window (and set half-window to N).
ESC-) RightArrow * Right one half screen width (or N positions).
ESC-( LeftArrow * Left one half screen width (or N positions).
ESC-} ^RightArrow Right to last column displayed.
ESC-{ ^LeftArrow Left to first column.
F Forward forever; like "tail -f".
ESC-F Like F but stop when search pattern is found.
HELP -- Press RETURN for more, or q when done
Extending command syntax
Various commands can be extended using options/arguments:
command [options] [arguments]
For example, the ls command is used to list files in a directory. This can be modified to show more/less detail:
# List all files
ls -a
# List all files with details
ls -l
# Combine options
ls -la
Finding commands
The which command is used to locate the executable file to be run for a command:
The which Command
# Find command location
which command_name
This will return a path such as /bin/mkdir.
The type Command
This is used to discover how commands will be interpereted by the shell. Fibd out if a command is an alias, shell built-in, file, keyword, or function:
# Show command type
type command_name
# Option to list the type and executable path if available
type -a command_name
Here are some examples (terminal output may differ):
| Command | Example return value |
|---|---|
type pwd | pwd is a shell builtin |
type -a file | file is /usr/bin/file |
type for | for is a reserved word |