search

Loading

Friday, July 12, 2013

How to save using vim editor with sudo privilege

Some times we will start editing the configuration files or the files which need root privilege in vi/vim and once we are about to save it, we will understand that we haven't edited it with sudo privilege.

It may be almost impossible to think quitting the editor without saving (:q!) and start it all over agin.



But not to worry, vi has the trick to quit the editor by saving it even if you haven't opened with sudo privilege.

So when you are in same situation, while saving use,

:w !sudo tee %

Then it will ask to type the sudo password, type the password. Now it is saved. Then you can type :q! quit it.

You can see that your changes has been saved. 

No comments :

Post a Comment