History expansion in bash shell
History expansion, much like the command
cd -
which moves you into the directory that you were in immediately prior to the current one, is an oft-overlooked but powerful and convienient mechanism for making your time in the shell more accurate, and for saving time.
The simplest form of this is:
$ grep -i somestring somefile
$ mv !$ /tmp
This will search the file somefile for the string somestring, and then move somefile into the directory /tmp.
Another common usage is the "quick substitution" command:
$ echo somefile
$ ^echo^cat^
This will echo the word "somefile" to STDOUT. The '^^^' command will execute the previous command, substituting the first parameter (echo) for the second (cat) - in this instance attempting to cat a file called somefile.
The HISTORY EXPANSION section of the bash(1) manpage details further modifiers, all in the same vein as vi commands, that can be used to further modify or search the command history.