Repeat last command with "sudo"
Solution 1:
You can write:
sudo !!
(See §9.3 "History Expansion" in the Bash Reference Manual.)
Solution 2:
Not enough?
sudo !!
if you want the S
simply put:
alias S=sudo
and use it
S !!
the !!
mean the last command
Solution 3:
Use alias redo='sudo $(history -p !!)'
. This is the only thing that I
have found that works with aliases. The other answers do not work in aliases for some reason, having tried them myself, even though they do work when directly running them.
Solution 4:
!!
can be used to reference the last command. So:
sudo !!