Pre-requirements
- Access to your cPanel account or SSH for command line usage.
- A basic understanding of text editors (both local and in-browser).
Editing Files Locally Using a Text Editor
You can easily edit your website files using a local text editor. Some popular text editors include:
Editing Files in cPanel File Manager
If you prefer to edit files directly on your server, cPanel provides an in-browser option for doing so:
- Once you have created your web hosting account and logged in to your cPanel account, scroll to the Files section and click on the File Manager icon.
- Navigate to the folder containing the file you wish to edit.
- Click on the file name to select it.
- Click on the Edit icon in the toolbar to open the file in the editor.
- Once the edit window opens, make your changes.
- Click Save Changes at the top of the window to save your edits.
Editing Files Using the Command Line (SSH)
If you prefer working with the command line, you can use terminal-based text editors like vi, vim, or nano to edit files:
vi filename.txt
vim filename.txt
nano filename.txt
Deleting Specific Lines from a File Using sed
If you want to delete specific lines in a file, you can use the powerful sed command:
Delete a Specific Line
To delete the 20th line from a file named contact.php:
sed -i '20d' contact.php
Delete the Last Line of a File
To delete the last line of the file:
sed -i '$d' contact.php
Delete Multiple Lines
To delete a range of lines, such as lines 10 to 55:
sed -i '10,55d' contact.php
Gotchas to Avoid
- When using sed, always double-check the line numbers and commands to avoid accidentally deleting the wrong lines.
- Always save a backup copy of your file before making changes using command-line tools.
Whether you're editing files locally using a text editor or directly in the cPanel File Manager, both methods are convenient ways to update your website. For command-line users, tools like vi, vim, nano, and sed provide advanced file manipulation options. Be cautious when making changes and always back up your files to avoid accidental data loss.
If you want to add to this tutorial or have found an error in it, please send an email to team+editorial@webhostingm.com