There are several useful features of the shell:
You can access your command history (previously typed commands) using the up and down arrows.
By pressing the Tab key, you can make the shell auto-complete command names and file/directory names until it encounters ambiguity.
For example, assuming that you have two text files, foobar
and foobaz
, in some directory with no other files in it, if you type emacs f
at the prompt and then press Tab without pressing Enter, you will see the name partially completed to
emacs fooba
on the screen. The shell can’t complete any further, however, since the last character could be r
or z
.
If you type !some_string
at the prompt and press Enter, the shell will check your command history for the most recently typed command beginning with some_string
and then automatically run that command. This can be useful if you typed a long command a while back and would rather not retype it or look through the command history to find it.[23]
If you mistype or omit something as you type a command, you can edit what you've typed (assuming that you haven't pressed Enter yet) without having to retype everything.
The commands for command line editing are similar to those listed in Table 5.2, “Moving the cursor in Emacs” (with the exceptions that M-<, M->, M-v, and C-v are unavailable) and Table 5.3, “Manipulating text in Emacs” (but only the commands under "Deleting Text" are available), which are for the text editor GNU Emacs.[24] You can also edit what you've typed with the left and right arrow keys and the Backspace and Delete keys.
To type a command like C-a, hold the Ctrl/Control key while typing a
.[25]
To type a command like M-f, hold the Alt (or the Esc) key while typing f
.[25]
In addition to the features listed above, GNU Bash (the Bourne-Again Shell) has other features[26] that you can learn about from the resources listed in Section A.3.1, “General information on the Bash shell” and the sections that follow.
[23] It's possible, though, that you typed the command so many commands ago that it's not in your command history, in which case the shell would respond with
some_string: Event not found.
[24] Emacs is discussed in Section 5.2, “GNU Emacs”.
[25] From the Emacs built-in tutorial.
[26] For example, if you're using Bash, try typing a single letter or a short string of letters (such as fi
) and then pressing Tab twice.