When I tried to edit the readonly file on EC2, it got stuck for a moment, so make a note. There are two ways to do it.
The simplest and easiest way.
Terminal
$sudo vim Select the file you want to edit
After editing with vim, you can save it with: wq as usual.
I think this is the most common pattern. I'm writing this because I became. No, I haven't run it with sudo after editing! Even if it becomes, just hit the following command without being impatient.
vim
:w !sudo tee %
#The contents are output
The meaning of each ** w **: Save **! **: Instruct subsequent commands ** sudo **: Run with administrator privileges ** tee **: A command that outputs a file and standard output at the same time. File overwrite is possible when combined with sudo **% **: Specify the currently open file
Then end with: q !.
vim
:q!
This will save it safely.
Recommended Posts