User login

Saving a read-only file after making a lot of changes before finding out

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

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.