Saving a file when you forgot to open it as root

LogicMonitor Development post
OK, this is not really related to monitoring, but Brandon Metcalf, one of our diligent TechOps superstars, posted this on our internal blog, and  I thought it was super handy, so I thought I’d share…

How many times have you opened a file in vi which is owned by root, made changes,  and then couldn’t save it because you didn’t sudo first? Sure, you could save it to an alternate location and then copy it into place, but the following is a handy trick:

:w !sudo tee %

This will save your file in place provided you have sudo privileges.


Steve Francis


Steve is the founder of LogicMonitor.

Subscribe to our LogicBlog to stay updated on the latest developments from LogicMonitor and get notified about blog posts from our world-class team of IT experts and engineers, as well as our leadership team with in-depth knowledge and decades of collective experience in delivering a product IT professionals love.

More from LogicBlog

Amps robot shadow

Let's talk shop, shall we?

Get started