The C shell will remember a number of previous commands. The number to
be saved is set with the shell variable history . The history
command will list all the commands previously known to the shell. A history
of commands can be saved over more than one login session using the shell
variable savehist.
% history
1 cd /usr/ctc/bin
2 ls -l
3 cd ../courses/unix
4 cd unix01
5 cc freda.c
6 history
To re-execute any of your (remembered) previous commands type
!command number
or you can type !? followed by enough characters of any
previous command to uniquely identify it. For example, both of the following
will re-execute command number 3
!3
!?courses
The last command can be repeated by typing !! which saves
having to remember the command number. Note, that in the tcsh the
up arrow key will also recall the previous command.
Help: for more information see the section on history
in csh(1) .
Previous commands can be modified, for example,
% cd /usr/local/src/Microemacs
no such directory!
% ^M^m
cd /usr/local/src/microemacs
Typing ^M^m means replace the string M in the
previous command with the string m and then execute the resulting
command.
To edit and execute a command that was not the most recent, it is necessary to precede the string replacement instruction with either the number of the command required, or a string that will uniquely identify the command.
% !24:s/M/m
cd /usr/local/src/microemacs
% !?Micro?:s/M/m
cd /usr/local/src/microemacs
Both of the above C shell commands would modify the incorrectly spelt
cd instruction in command 24. The extra ?
in the last example is to stop the shell looking for a command that contained
the text Micro:s/M/m.
Help: for more information see csh(1). Once in the manual
pages type /History Substitution to search forward through
the screens.