How "sudo !!" works in bash:
$ touch /bin/1
touch: cannot touch `/bin/1': Permission denied
$ sudo !!
sudo touch /bin/1
How "sudo !!" works in bash:
$ touch /bin/1
touch: cannot touch `/bin/1': Permission denied
$ sudo !!
sudo touch /bin/1
bash support a history expansion feature. History expansions are implemented by the '!'. '!!' refer to the previous command.
History expansion is performed immediately after a command line is read, before execve() system call.
$ touch /bin/1
touch: невозможно выполнить touch для «/bin/1»: Отказано в доступе
$ sudo strace !!
sudo strace touch /bin/1
execve("/usr/bin/touch", ["touch", "/bin/1"], [/* 17 vars */]) = 0
bash expansion "sudo !!" to "sudo touch /bin/1" and then run command.
sudo !!
is just telling the terminal to run the previous command, but this time under sudo. In this case it is the same as just typeing sudo touch /bin/1
the first time.