Code Yarns ‍👨‍💻
Tech BlogPersonal Blog


📅 2014-Jul-17 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ sudo, sudoedit, vim ⬩ 📚 Archive

When I need to edit files with superuser privileges, like those in etc directory, I used to do:

$ sudo vim /etc/hosts

This launches the editor with root privileges.

I recently learnt that there is a safer and more elegant way do this: using sudoedit. This makes a temporary copy of the file you want to edit in /tmp and opens it in your favorite editor with normal user privileges. After you save the file, the original file is replaced with the updated copy.

To do this:

$ sudoedit /etc/hosts

Or equivalently:

$ sudo -e /etc/hosts

Tried with: Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧