The following steps show how to edit a text file in Ubuntu Server 18.04 using the terminal.
In these examples we’ll show how to use vi Editor and Nano to open, edit and save a text file.
How to edit a file using vi Editor
- Using the terminal, navigate to the directory where the file is saved
- Enter the following command to open the file in Vi – where test_file.txt is the name of the file
-
vi test_file.txt
- When vi Editor is first started it is in “command mode”
- Press i on your keyboard to enter “insert mode” – which allows you to insert text into the file
- Use the arrow keys your keyboard to navigate to where you need to edit the text and edit as required
- To save and exit – press Escape then Shift + Z and Shift + Z again
How to edit a file using Nano
- Using the terminal, navigate to the directory where the file is saved
- Enter the following command to open the file in Vi – where test_file.txt is the name of the file
-
nano test_file.txt
- Use the arrow keys your keyboard to navigate to where you need to edit the text and edit as required
- To save and exit – Ctrl + X then Y