17.6 Useful Features of the Shell
As you probably noticed in the examples above, entering commands in Bash can
include a lot of typing. In the following, get to know some features of the Bash that
can make your work a lot easier and save a lot of typing.
History
By default, Bash “remembers” commands you have entered. This feature is called
history. You can browse through commands that have been entered before, select
one you want to repeat and then execute it again. To do so, press [↑] repeatedly
until the desired command appears at the prompt. To move forward through the
list of previously entered commands, press [↓]. For easier repetition of a certain
command from Bash history, just type the rst letter of the command you want
to repeat and press [Page ↑].
You can now edit the selected command (for example, change the name of a le
or a path), before you execute the command by pressing [Enter]. To edit the
command line, just move the cursor to the desired position using the arrow keys
and start typing.
You can also search for a certain command in the history. Press [Ctrl] + [R] to
start an incremental search function. showing the following prompt:
(reverse-i-search)`':
Just type one or several letters from the command you are searching for. Each
character you enter narrows down the search. The corresponding search result
is shown on the right side of the colon whereas your input appears on the left of
the colon. To accept a search result, press [Esc]. The prompt now changes to its
normal appearance and shows the command you chose. You can now edit the
command or directly execute it by pressing [Enter].
Completion
Completing a lename or directory name to its full length after typing its rst
letters is another helpful feature of Bash. To do so, type the rst letters then press
[→|] (Tabulator). If the lename or path can be uniquely identied, it is completed
at once and the cursor moves to the end of the lename. You can then enter the
next option of the command, if necessary. If the lename or path cannot be
uniquely identied (because there are several lenames starting with the same
letters), the lename or path is only completed up to the point where it becomes
ambiguous again. You can then obtain a list of them by pressing [→|] a second
time. After this, you can enter the next letters of the le or path then try comple-
tion again by pressing [→|]. When completing lenames and paths with the help
of [→|], you can simultaneously check whether the le or path you want to enter
really exists (and you can be sure of getting the spelling right).
Wild Cards
You can replace one or more characters in a lename with a wild card for path-
name expansion. Wild cards are characters that can stand for other characters.
There are three dierent types of these in Bash:
Shell Basics 205