Home ›
Saving a read-only file after making a lot of changes before finding outSaving a read-only file after making a lot of changes before finding out
Submitted by Benjamin Melançon on September 26, 2007 - 6:44pm
If you accidentally do a lot of edits in vi to a read-only file, or rather a file to which you do not have write permission and forgot to sudo in, you can do the following to save it elsewhere temporarily and then overwrite the original.
Let's say its name is recalcitrant file:
From inside vi:
:sav ~/temporary.file
:q
<code>
Then:
<code>
sudo mv ~/temporary.file recalcitrant.file
Pitfalls: you should check the owner of the file you were trying to edit and set your temporary file back to that
Otherwise you can get this lovely and unusually uninformative error message.
ben@agaric:/etc$ sudo postmap /etc/postfix/virtual_alias_maps
postmap: fatal: open /etc/postfix/virtual_alias_maps.db: Permission denied
Comments
Post new comment