How often have you typed a command in the Linux Shell, after which
you're finding out you left out Sudo to the whole deal? With a bit of
luck you're getting an error. Worst case scenario is editing a read
only config file because of the lack of permissions. This happens to me a lot, so i'll share the best solution I can think of to correct it.
The "!!" syntax tells Bash to pull out the last command, with the possibility of adding a prefix or suffix. This means you can add " | more " to the last command by typing " !! | more ". You can also add the forgotten sudo to the command by typing " sudo !! ".
Try this as an example:
Which results in editing a config file you can't save. This is the solution:
You'll see the command you typed earlier right away, with the sudo you added, and the password prompt appears.
This is what you'll see:
tim@bytemods:~$ vi /etc/php5/apache2/php.ini
tim@bytemods:~$ sudo !!
sudo vi /etc/php5/apache2/php.ini