Solaris Advanced User's Guide

Repeating Commands in the Bourne Again, C, TC, or Z Shell

If you use the Bourne Again, C, TC, or Z shell, type !! and press Return to repeat the last command you typed.

Tue Oct 31 15:18:38 MST 2000

You can also repeat any previously typed command by typing !x, where x is the desired command's corresponding number on the history list. To see the history list, type the history command and press Return. The following is an example of what you might see.

example% history
1  pwd
2  clear
3  ls -l
4  cd $HOME
5  logname
6  date
7  history

Note –

The Z shell does not display the history command in the history list.

Another method for repeating characters from the history list is to follow the ! with a negative number. For example, to repeat the second from the last command on the history list, type the following command.

example% !-2
Tue Oct 31 15:20:41 MST 2000

Note –

If you use this command repetition method immediately after the history command in the Z shell, increase the negative number after the ! by one (!-3).

Using the previous example history list, the date command is repeated.

You can also type the ! character, followed by the first few characters of a previous command to repeat that command. For example, if you had previously typed the clear command to clear your screen, you could type !cl to clear your screen again. With this method for repeating commands, however, you must use enough characters for the desired command to be unique in the history list. If you use only one letter after the !, the system repeats the most recent command that begins with that letter.