oops, i edited and i’m not root

  • August 28, 2012
  • vi

the amount of times i have been editing away at a file in vi and gone to save it only to realise i’m not root…

if my edits were all in one block, i’d usually end up copying the text with my mouse, closing the file, su to root, open it up, paste, zzz….

so. without the pain and agony, we do:

:w !sudo tee %

:w is asking to write the file,
sudo obviously asks to run this as root,
tee will will also send the output to a file, which is %.
% is the current file.


No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *