Using sudoedit to sudo… edit

Software

I got into a lot of trouble last time I wrote a post with a title like this. Let’s tempt fate again!

We haven’t had a things you already know, unless you don’t post for at least a few months, so here’s something that still surprises some people.

Instead of doing this:

$ sudo vi ./file

You can do this:

$ sudoedit ./file

Safer, easier, better :).

From the manpage(8), the tool creates a temporary copy of the file, then invokes whichever editor you have defined in SUDO_EDITOR, VISUAL, or EDITOR. When you’re done editing, the temporary modified file is copied back to the original location.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.