Lesson 15: Editing text files with Nano¶
Nano is a basic text editor available in most Linux distributions. There are other editors available such as vim, emacs and gedit (graphical) however, this page expands on Nano. We recommend learning how to use Nano before attempting to use other editors.
We can open a file by typing:
[learner planets]$ nano earth.txt
You should see that Nano has opened the 'earth.txt' file with the two existing facts, added in previous tutorials.
Editing Files¶
Once a file has been opened in Nano, you can navigate around the file
using the arrow keys. To insert text, move the cursor to the desired
location and start typing. Pressing the Backspace
or Delete
key will
delete text in front of the cursor or at the cursor, respectively.
To add our third fact about Earth, press the down arrow key twice to place the cursor on the third line and start typing. The example we are using is 'Earth is the only planet not named after a mythological god or goddess.' You may copy and paste this directly into Nano, type it out or use your own fact, the choice is yours.
Program Functions¶
The bottom section of Nano contains the program functions which include: saving and quitting.
Saving Files¶
To save a file, use the ^O
(Ctrl-o
) function and hit Enter
. You
may change the filename to save to a different file however, as we want
to overwrite the existing file, do not change the filename.
Quitting the Application¶
After saving a file with no further modifications, using the ^X
(Ctrl-x
) function will close Nano. If modifications have been made
since the last save, Nano will first prompt if you want to save the
document before quitting. Entering n
here will destroy all changes
since the last save. Entering y
will start the process described in
the 'Saving Files' section above.
Further Reading¶
A more thorough tutorial of Nano is available here