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
dangerous.

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 gnu.emacs.help, 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."
(interactive)
(when buffer-file-name
(find-alternate-file
(concat "/sudo:root@localhost:"
buffer-file-name))))

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
please.

Xah
http://xahlee.org/


.



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. ...
    (SuSE)
  • 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. ...
    (comp.lang.java.programmer)
  • 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. ...
    (comp.sys.mac.system)
  • 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 ...
    (comp.os.linux.misc)
  • 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 ...
    (comp.lang.tcl)