How to Save file in vi not opened with sudo


It has happened to me a lot of times that i edit a file in vi. I insert and edit a lot and finally when I try to save it I find that I dont have permission for it. If only I had opened it with sudo. I found a solution for this issue. It was actually a simple command and here it is

:w !sudo tee %

Just use the above command in command mode in vi and that’s it and it will ask for reloading the file and then reload it and exit it using :q!
because we have already written to the file and no need to save the file again.
Try it out and tell me.


, , , ,

  1. #1 by Roopa on December 27, 2009 - 10:37 am

    wow :)
    thanks..

  2. #2 by Professional SEO Company on December 30, 2009 - 11:33 pm

    thats very usefull stuff.
    thanks for sharing it..good job.

  3. #3 by السعوديه on January 3, 2010 - 12:59 am

    thank you dear …

    nice .

(will not be published)