I frequently find myself typing similar commands successively. Are there shortcuts available to help me?
Yes. First of all, the arrow keys on your keyboard can almost always be used for navigating through the command history and editing the command line. Second, almost every shell has specific commands to repeat or edit commands. The most frequently used shortcuts of the standard Bourne Again Shell bash
and the enhanced C shell tcsh
are the following:
!!
repeat the last command
!$
insert the last word of the last command
!xyz
repeat the last command starting with xyz
!number
repeat command number number from the history list
history | more
return a list of the last commands entered with their numbers
Additionally, the bash
and tcsh
have a feature called word completion: Type the first few characters of a word, then press the tab key. The shell will complete the word as best as it can. If the completion is not unique, pressing tab again (or ctrl-D
in case of the tcsh
) returns a list of possible completions. A word in this context is either a command (if it is the first word on the command line) or a file name (if it is not the first word on the command line).
Note that the Korn shell ksh
has different shortcuts; see the ksh manpage for details.