Vim save a read only file
Learn more. Using vim to force edit a file when you opened without permissions Ask Question. Asked 8 years ago. Active 3 years, 9 months ago. Viewed k times. Improve this question. This question seems to have already been answered here: stackoverflow. My apologies. I didn't find that response. Thank you. Use the [Vim write with sudo trick][1] :w! Add a comment.
Active Oldest Votes. There seems to be some different approachs, depending on your current problem: Readonly by vi. If your file has :set readonly you can Use :w! Issue: :w! This will write the buffer to tee , a command that receives pipe information and can write to files. And as tee is run with sudo powers, tee can modify the file. A permission problem no sudo : you don't have rights to write the file and you don't have admin access.
Use :w! Improve this answer. DrBeco DrBeco 1, 1 1 gold badge 16 16 silver badges 15 15 bronze badges. And with your anonymous like I just earned the necromancer badge! I feel like defending Mordor now. Open the file with the vim readfile.
From the screenshot above, the file we added actually write to the existing file contents. But why did it happen so? The common answer to this is because the folder privileges override the files privileges. For instance, if we use ls -l to view the folder readonly , we will realize that the owner which is me in this case still have the write privileges. And because I can write to the folder I have the right privileges to write to the files inside it. And maybe open the file again again with sudo: and make all the changes again with so much time wasted.
What simply takes place when using the :w! The tee command now runs in a privileged environment and redirects its stdin to filename. Skip to content Search for: Search Close. Close Menu. Thank you for reading this post. Kindly share it with others.
At this point we will be presented with the content of the file and a prompt to press ENTER or type another command. Thank you for this!! Too many face palm! This worked for me. Thanks, saved me three times now. First result on Yahoo search makes it easy to get back here too. Awesome man.. Thanks for not letting me copy and paste the command in the article.
0コメント