In VI/VIM editor,Make changes in file without root user even if file has root permissions.

Hi Guyes,

This is very common problem that every software engineer has may suffered since from student level.

Problem Statement-

In vi/vim editor,Suppose you have created a file and saved it using root user.
And now there is a situation that you have opened this file using without root user and you are trying to write in file and save it.

Then we get an error like file is readonly or you can not save it.

what normal people do –

Normally people quit the file without saving(as they not able to save the file).
(:q!) and they change the user to root user / change the permission of file,open the file and write in it and save it.

But as we are software engineer, we have habit to forgot, and in a scenario mentioned in above problem statement we dont want to do the stuff as normal people does or want to save the time and efforts (haha).

What this blog reader do in the above senario(solution)-

(:w !sudo tee %)

esacpe : !sudo tee % and enter ….by doing this you will able to save the changes in the file. And you have to do :q! to exit from the files

Advertisements

2 thoughts on “In VI/VIM editor,Make changes in file without root user even if file has root permissions.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s