emacs: editing 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 prone 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."
  (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 preferred.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs