The bash and zsh shells are very similar, with zsh being more
of a “power-house” shell than bash. Key commands for both shells are
similar and knowing these time-saving shortcuts can be a great boon for those
using the shell often. Most of these commands are used for quick navigation or editing
of the current command line.
To move to the beginning of the current line, use [Ctrl][A]. To
move to the end of the current line, use [Ctrl[E]. To move the cursor forward
one word on the current line, use [Alt][F]; to move the cursor backwards one
word on the current line, use [Alt][B].
You can also use key commands to do more than move around on
the current line. They can be used to manipulate text on the current line as
well. For instance, use [Ctrl][U] to clear the characters on the line before
the current cursor position and [Ctrl][K] to clear the characters on the line
after the current cursor position. Bash and zsh work slightly different here. In
zsh, [Ctrl][U] clears the entire line instead.
To delete the word in front of the cursor, use [Ctrl][W]. To
delete the word after the cursor, use [Alt][D].
You can also search history quickly using [Ctrl][R]. In bash,
you’ll be given a prompt:
(reverse-i-search)`':
You’ll see this in zsh:
bck-i-search:
Type what you’d like to search for, such as ssh, and you’ll get the first matching
entry in the history. Continue pressing [Ctrl][R] to search further back in the
history for all entries that contain ssh.
When you find the one you want, press [Enter]. If you need to modify a command
that you find, use the right arrow to break out of the search and make the changes
you need.
Shortcuts can be used to change the case of words as well. To
make the current word after the cursor uppercase, use [Alt][U]. To make it lowercase,
use [Alt][L]. Note that cursor position here is important, if the cursor is midway
in the word, only the part of the word after the cursor will have the case
changed. To capitalize a word, use [Alt][C] (this is also cursor-position-dependent;
if the cursor is midway in a word, that letter will be capitalized).
Keyboard shortcuts save steps and knowing these few shortcuts
when working on the command-line can save a lot of time and typing.
Delivered each Tuesday, TechRepublic’s free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!