Knowledgebase

Editing Files from the Command Line Print

  • developersgitdeployment, developers, php, wordpress, filemanager, htaccess, uploads, guide
  • 0

Making changes without a file manager.

THE EDITORS

nano is simple. Controls are shown at the bottom of the screen, and it behaves as you would expect. vim is powerful with a steep learning curve. If you do not already know it, use nano.

A BASIC NANO SESSION

Open the file, make changes, save with the displayed key combination, exit.

BEFORE EDITING ANYTHING IMPORTANT

Copy it first. A dated copy alongside the original costs nothing and is your way back.

This applies especially to wp-config.php, .htaccess and .env. A mistake in any of these takes the site offline.

VIEWING WITHOUT EDITING

cat for short files, less for long ones. Safer when you only need to read.

WHEN NOT TO USE THE COMMAND LINE

For substantial edits, download the file, edit it properly, and upload it. Editing a long file in a terminal invites mistakes.

CHECKING SYNTAX

For PHP files, running php -l against the file checks syntax without executing it. Do this before reloading a site.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot