1

If I have a file I want to edit, as root, I should have the ability to modify it regarless of the permissions. But this does not seem to be the case with all text editors, emacs in particular.

If there is a text file with any of the following permissions, with the permissions -rw-r--r--, -r--rw-r--, or -r--r--rw- then as root, I can edit the file, no problem. However, if there are no write permissions at all (-r--r--r--), then emacs will not allow root to even make changes to the buffer. Vim behaves in a slightly quirky way as well. For the first three cases, it will allow root to save changes with the :w command, but in the last case, root must use the override :w! command to save.

Both nano and gedit behave properly, giving the super user write access all the time.

Does anyone know what the source of this obnoxious behavior is on the part of emacs and vim? I'm inclined to think it's more of a side-effect of something, rather than an intentional design, based on vim's behavior, but I can't think of what would cause this.

1 Answer 1

1

This is more of a case of vim and emacs exposing what is going on under the hood. When there are no write permissions available to the file, it is not being edited in-place. Instead, the file is entirely replaced (since that depends on directory permissions, not file permissions).

To save a file in emacs that does not have write permissions, you can use M-x toggle-read-only or C-x C-q. You will then be able to save your modifications.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .