1.^r
in bash begins a reverse-search-history with command completion
Press ctrl+r in a bash shell and type a few letters of a previous command
I can't imagine how much typing this has saved me.
2.history
and !number
Run the specified command with it's history number
$ history
# will output like below
27 rvm install 2.0
28 ruby use 1.9.3
29 rvm remove 2.0.0
30 cd ../server
31 rvm remove 1.9.3
32 rvm install 1.9.3
# use the history number run specified command
$ !32
# is same as
$ rvm install 1.9.3
3.sudo !!
Run the last command as root
Useful when you forget to use sudo for a command.
"!!" grabs the last run command.
4.!!:gs/foo/bar
Runs previous command replacing foo by bar every time that foo appears
Very useful for rerunning a long command changing some arguments globally.
As opposed to ^foo^bar, which only replaces the first occurrence of foo, this one changes every occurrence.
5.!*
Reuse all parameter of the previous command line
!* is all of the arguments to the previous command rather than just the last one.
This is useful in many situations.
6.!:-
Insert the last command without the last argument (bash)
$ /usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.google.com/
# then
!:- http://www.commandlinefu.com/
# is the same as
$ /usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.commandlinefu.com/
7.!$
Insert the last argument of previous command (bash)
$ ping www.google.com
# then
$ traceroute !$
# is the same as
$ traceroute www.google.com