Using vi in Debian to Edit a File and Fix a Broken WordPress Plugin

Recently I needed to quickly log in to my Debian servers to edit a file with a quick fix that was bringing down my WordPress sites.

The reason it brought my sites down, is because I have all my plugins set to update automatically. This may sound like a bad idea and if a breaking change comes through in a plugin update, like what happened in this instance, it is a bad idea.

Anyway, I digress. If you are not doing it everyday it is not always intuitive about how to navigate around and do file changes in Linux.

I like to create my own “cheat sheets” that I can refer to later. Trusted commands that I know I can run safely because I have used them in the past.

Anyway here are the simple steps, to save time in the future.

Connect via SSH or your preferred method to your Server.

Navigate to the site folder. E.g:

/var/www/html

Once you have found the relevant folder open the file you want to edit:

E.g:

sudo vi filename.php

* to insert text

Use ESC to change focus from editing to not editing.
: x! to save

If you want to exit without saving

:q!

Hopefully this will help you quickly edit a file in a time of crisis.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply