A lot of the time I edit a file with nano, try to save and get a permission error because I forgot to run it as sudo. Is there some quick way I can become sudo without having to re-open and re-edit the file?
No, you can't give a running program permissions that it doesn't have when it starts, that would be the security hole known as 'privilege escalation'.
Two things you can do:
Edit: See this related question for other solutions in advanced editors that allow writing the file buffer to a process pipe.
|show 2 more comments|
I just tried
Here's a (basic) script that does that.
It checks if you can edit the file, and if you can't, it runs "nano" as root instead.
/usr/local/bin/edit (or ~/bin/edit)
And a command I called
/usr/local/bin/view (or ~/bin/view)
There's already a program called