Repeating the Last Command
Problem
You just typed a long and difficult command line, one with long pathnames and complicated sets of arguments. Now you need to run it again. Do you have to type it all again?
Solution
There are two very different solutions to this problem. First, just type two exclamation marks at the prompt, and bash will echo and repeat the previous command. For example:
$ /usr/bin/somewhere/someprog -g -H -yknot -w /tmp/soforthandsoon ... $ !! /usr/bin/somewhere/someprog -g -H -yknot -w /tmp/soforthandsoon ...
The other (more modern) solution involves using the arrow keys. Typing the uparrow key will scroll back through the previous commands that you have issued. When you find the one you want, just press the Enter key and that command will be run (again).
Description
The command is echoed when you type !! (sometimes called bang bang) so that you can see what is running.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access