Correcting Commands

Sometimes you may type a command incorrectly, causing Linux to display an error message. For example, suppose you typed dat instead of date:

[bill@home bill]$ dat
bash: dat: command not found

In such a case, carefully check the spelling of the command and try again. If you notice an error before pressing Enter, you can use the Backspace key to return to the point of the error and then type the correct characters.

Just as a web browser keeps track of recently visited sites, the bash shell keeps track of recently issued commands in what’s known as the history list. You can scroll back through bash’s history by using the Up arrow key, or back down using the Down arrow key, just as you would with the Back and Forward buttons on a web browser. To reissue a command, scroll to it and press Enter. If you like, you can modify the command before reissuing it. When typing shell commands, you have access to a minieditor that resembles the DOSKEY editor of MS-DOS. This minieditor lets you revise command lines by typing key commands. Table 7-1 summarizes some useful key commands interpreted by the shell. The key commands let you access a list of the 500 most recently executed commands, saved in the ~/.bash_history file.

Table 7-1. Useful Editing Keystrokes

Keystroke(s)

Function

Up arrow

Move back one command in the history list.

Down arrow

Move forward one command in the history list.

Left arrow

Move back one character.

Right arrow

Move forward one character. ...

Get Learning Red Hat Linux, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.