“Those who cannot remember the past are condemned to repeat it.” – George
Santayana, (c/o Wikipedia)
Sometimes I want to remember the past so I’m able to repeat it. (I’m always
looking for ways to save a few keystrokes.) I just found out I can run Linux
commands from my history with event designators like this:
$ !svn
svn co http://svn.example.com/svn/ExampleProject/trunk .
Typing !svn
will run the last svn
command I ran, which is much easier than
retyping this:
$ svn co $s/ExampleProject/trunk .
($s is set to the root of my SVN repository to save some typing.)
Using !svn
is also faster than using the up arrow to scroll back to my last
svn
command, as this often requires me to hit the up arrow several times
until I find it, and sometimes I scroll right past it and it ends up taking a
lot longer than it would for me to just retype it.
You can also use history to show the most recent commands you’ve executed, and
then use the event designator (!N
) to run the Nth command in your history:
$ history
...
636 svn log -l 10
637 svn up
638 history
$ !637
svn up
At revision 828.
Pipe history
into grep
for an abbreviated list.
You can see other useful history commands in this article.