Command-line tasks tend to be keyboard intensive. Of course, each character typed increases the likelihood of typing errors creeping in. In order to reduce the typing required, and—more importantly—reduce the opportunity for errors, virtually all modern command-line environments include tab completion (sometimes called tab auto-completion) and access to the command history.

Note that these are not simply convenience features! Because they help reduce typing errors (significantly), we strongly recommend that you learn to use tab completion and the command history, and use them whenever possible.

Tab completion

Conceptually, this is a simple feature available in most shells—however, different shells have different wrinkles in the implementation.

Windows Command Prompt

In the Command Prompt program, pressing the Tab key at some point where Command Prompt expects a file or directory name to be typed causes the first matching entry to appear on the command line; each successive Tab key press cycles through the remaining matches, one at a time. If the first few characters of a file or directory name have already been typed, that will restrict the set of possible matches to just those entries that match the characters typed.

In general, Command Prompt will perform tab completion at the start of the command line, after one or more spaces, after an equals sign, or after the semicolon character. If tab completion is needed following some other character, it’s generally necessary to insert a space, use tab completion, and then use the left-arrow key to go back and remove the space before executing the command.

Command Prompt does not support tab completion for completing internal commands, or for commands located on the PATH, but not in the current directory (or in the directory typed so far in the command line).

Bash shell, including OS X & Ubuntu Terminal, Git Bash, etc.

In a Bash shell, pressing the Tab key at some point where a command, file, or directory name is expected invokes tab completion. If the characters already typed uniquely identify an entry, it will appear on the command line. Otherwise, the shell will emit an alert/beep sound, and nothing will appear immediately—but a second press of the Tab key will display a list of all matching entries, allowing the user to refine the partial name typed.

In general, the Bash shell will perform tab completion at the start of the command line, after one or more spaces, after an equals sign, or after the colon character. If tab completion is needed following some other character, it’s generally necessary to insert a space, use tab completion, and then use the left-arrow key to go back and remove the space before executing the command.

Command history

To access the command history, use the up-arrow key to scroll through previously entered commands; if you scroll too far, use the down-arrow key to return to more recently typed commands. At any point, when a previous command is displayed on the command line, hitting the Enter key will execute that command. Even if no previous command is exactly what you need at the moment, you may be able to scroll through the previous commands and find one that is close, and then use the left- and right-arrow keys to edit the command before submitting it. (Don’t attempt to use the mouse to make such changes; while you can generally select text to copy to the clipboard, and then paste that text on the command line, most command line programs will not move the editing/insertion point in response to mouse clicks.)