Obtaining origin approvals on a documents within vi?
Usually while editing and enhancing config documents, I'll open one with vi and afterwards when I most likely to wait understand that I really did not type
sudo vi filename
Exists any kind of means to offer vi sudo advantages to conserve the documents? I appear to remember seeing something concerning this while seeking out some things concerning vi a while earlier, today I can not locate it.
When you enter into insert setting on a documents you require sudo accessibility to modify, you get a standing message claiming
-- INSERT -- W10: Warning: Changing a readonly file
If I miss out on that, usually I do
:w ~/edited_blah.tmp
:q
. after that.
sudo "cat edited_blah.tmp > /etc/blah"
. or.
sudo mv edited_blah.tmp /etc/blah
There is possibly a much less periphrastic means to do it, yet it functions.
A fast hack you can take into consideration is doing a chmod on the documents you're editing and enhancing, conserve with strength, and afterwards chmod back to what the documents was initially.
ls -l test.file (to see the permissions of the file)
chmod 777 test.file
[This is where you save in vim]
chmod xxx test.file (restore the permissions you found in the first step)
Of training course I do not advise this strategy in a system where you're bothered with security, when it comes to a couple of secs any person can read/change the documents without you understanding.
A fast Google appears to offer this suggestions :
- Don't attempt to modify if it's read - just.
- You could be able to transform the approvals on the documents. (Whether or not it will certainly allow you conserve depends on trial and error.)
- If you still modified anyhow, conserve to a short-lived documents and afterwards relocate.
Ryan's suggestions is usually excellent, nonetheless, if adhering to action 3, do not relocate the short-lived documents ; it'll have the incorrect possession and also approvals. Rather, sudoedit
the proper documents and also read in the materials (making use of :r
or such) of the short-lived documents.
If adhering to action 2, make use of :w!
to compel the documents to be created.
In basic, you can not transform the reliable customer id of the vi procedure, yet you can do this :
:w !sudo tee myfile
Related questions