How can I repeat commands?
One of the biggest advantages of using the shell is that it makes it easy for you to do things over again. If you run some commands, you can then press the up-arrow key to cycle back through them. You can also use the left and right arrow keys and the delete key to edit them. Pressing return will then run the modified command.
Even better, history
will print a list of commands you have run recently.
Each one is preceded by a serial number to make it easy to re-run particular commands:
just type !55
to re-run the 55th command in your history (if you have that many).
You can also re-run a command by typing an exclamation mark followed by the command's name,
such as !head
or !cut
,
which will re-run the most recent use of that command.
This exercise is part of the course
Introduction to Shell
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
