Logged in to vi, made changes, forgot to sudo first - now what
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Ocean Floor
--
Chapters
00:00 Logged In To Vi, Made Changes, Forgot To Sudo First - Now What
00:27 Accepted Answer Score 11
00:45 Answer 2 Score 40
01:07 Thank you
--
Full question
https://superuser.com/questions/53733/lo...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #permissions #sudo #vi
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Ocean Floor
--
Chapters
00:00 Logged In To Vi, Made Changes, Forgot To Sudo First - Now What
00:27 Accepted Answer Score 11
00:45 Answer 2 Score 40
01:07 Thank you
--
Full question
https://superuser.com/questions/53733/lo...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #permissions #sudo #vi
#avk47
ANSWER 1
Score 40
From SO:
:w !sudo tee %
I actually find myself using this way to do it more frequently now:
:%!sudo tee %
I think it's a little more intuitive, as I know what :%!
does, whereas I don't have a visceral understanding of :w !
. Also, it's easy to miss the very important space between the w
and the !
.
ACCEPTED ANSWER
Score 11
In this case, I write the file with :w /tmp/tmpfile
. Then I go out and move /tmp/tmpfile
to my old file with sudo rights.