how to edit a file as admin

Another little emacs tip. The tip is about how to edit files that
requires admin privilege.

Often, you want to edit a file that requires admin privilege. So,
either you start another emacs instance as root, or, modify the file's
permission first with sudo then edit then modify it back. Both
solutions are painful.

Starting another emacs instance is slower, and you also need to
navigate to the dir path. Edit permission bits is error pron and

When i was a full time unix sys admin, i usually always keep a
instance of emacs as root, with different colored background. But this
is also not a optimal solution.

Here's one short tip from the web:

; from newsgroup, by Richard Riley, 2009-08-02
(defun open-current-file-as-admin ()
"Open the current buffer as unix root.
This command works on unixes only."
(when buffer-file-name
(concat "/sudo:root@localhost:"

PS the above works in unixes only (including linuxes and Mac OS X).
How does one do on Windows? If you know, please post! Concrete
solution that you actually use is prefered. No general reference



Relevant Pages

  • Re: [SLE] Hex / ascii / Text editor recomendations please
    ... > recall them all. ... > and edit files in hex format, but I'd be surprised if it couldn't do it. ... > Emacs simply does everything. ...
  • Re: Great SWT Program
    ... None of the nasty things that you have said or implied about me are at ... but that's not what emacs is. ... multiple top-level windows, ... over and over again for each instance you need to do an edit near. ...
  • Emacs too slow for casual editing [was Re: Formatting Posts With VI]
    ... > postponed post is just not fast enough. ... And besides, Emacs isn't the ... > right tool if all one wants to do is edit a file, ... > time one logs into the system and be closed when one logs out of the ...
  • Re: Running an application more than once
    ... It is up to the program developer to ... developers for Emacs rather explicitly recommend the opposite. ... You edit one file and then exit the editor. ... and do all your editing in the same Emacs session. ...
  • Re: Tcl Cross Platform Editors - your top five.
    ... I can't compile Vim on some of these ... platforms for various reasons and Vi is not sufficient. ... Emacs is the best and should compile and or have packages for all ... If you can ssh into a box then you can edit ...