2

I can run a command like this:

tim@Hairy:~$ echo Hello
Hello

Then I can run the command !! and it does it again:

tim@Hairy:~$ !!
echo Hello
Hello

I can even run it with another argument to the previous command:

tim@Hairy:~$ !! World
echo Hello World
Hello World

So what is the !! actually doing? I have struggled to search for it because a Google for !! is fairly... pointless.

Tim
  • 33,500

3 Answers3

10

It's part of bash's history interaction.

  • A !! is substituted with the last command as is.
  • A !foo is substituted with the last command that started with foo.
  • A !^ or a !$ is substituted with the first or last arguments respectively in the previous command.
  • A !n is replaced with the nth command in history.
  • A !-n is replaced with the nth-last command in history.
  • ...
muru
  • 207,228
4

It's a very short answer:

!! repeats the last command, nothing else.

More "funny" things can you find here.


I have struggled to search for it because a Google for !! is fairly... pointless.

And a better search for that is this:

https://www.google.de/webhp?q=bash+cheat+sheet
A.B.
  • 92,125
2

From man bash:

!!   Refer to the previous command.  This is a synonym for '!-1'.

Test:

$ echo "foobar"
foobar

$ !!
echo "foobar"
foobar

$ !-1
echo "foobar"
foobar
heemayl
  • 93,925