Tuesday, March 31, 2009

saving a file in VI as root

It often happens that you open up a file for editing using vi or vim and only when you come to save the file, you realise you did not open the file with root privileges and are unable to save the file.

when you type :wq!
you get E212: Can't open file for writing.

If that happens to you , simply type

:w !sudo tee %

you will be asked for your sudo password
enter your password and
press enter when asked

(vi/vim will detect that the file has been changed and ask whether you want
it to be reloaded.)

As a shortcut, you can define your own command.

Put the following in your /etc/vimrc

command W w !sudo tee % > /dev/null

and then in future simply type

:W

2 comments:

Anonymous said...

Hey,
I owm a number of FLV files which I've been trying my best to convert to avi or mpg with the help of both [url=http://www.topvideoconverter.com/flv-to-mpeg-converter/]flv to mpeg converter[/url] and SUPER. Both of them convert Fine, EXCEPT I cannot get the Sound and VIDEO to sync.
I've tried matching the fps rate for the import file to the outcome file.
Any suggestions will be well appreciated!
Thanks very much!

CG said...

mencoder does a good job of converting just about any video format.
yum install mencoder or apt-get install mencoder
then follow instructions here.
http://cgerada.blogspot.com/2008/07/save-convert-and-join-youtube-movies.html