Editing a File
You want to run an editor from the command line to change a config file.
Use the editor nano included with most Raspberry Pi distributions.
Discussion
To use nano, simply type the command nano followed by the name or path to the file that you want to edit. If the file does not exist, it will be created when you save it from the editor. However, this will only happen if you have write permissions in the directory where you are trying to write the file.
From your home directory, type the command nano my_file.txt to edit or create the file nano my_file.txt. Figure 3-4 shows nano in action.
You cannot use the mouse to position the cursor; use the arrow keys instead.
The area at the bottom of the screen lists a number of commands that you access by holding down the Ctrl key and pressing the letter indicated. Most of these are not that useful. The ones that you are likely to use most of the time are:
Ctrl-X
Exit. You will be prompted to save the file before nano exits.
Ctrl-V
Next page. Think of it as an arrow pointing downward. This allows you to move through a large file a screen at a time.
Ctrl-Y
Previous page.
Ctrl-W
Where is. This allows you to search for a piece of text.
There are also some fairly crude cut-and-paste type options there, but in practice, it’s easier to use the normal clipboard based on the menu that you access with a right-click (Figure 3-5).
Using this clipboard also allows you to copy and paste text between other windows such as your browser.
When you’re ready to save your changes to the file and exit nano, use the command Ctrl-X. Type Y to confirm that you want to save the file. nano then displays the filename as the default name to save the file under. Press Enter to save and exit.
If you want to abandon changes you have made, enter N in place of Y.
See Also
Editors are very much a matter of personal taste. Many other editors that are available for Linux will work just fine on Raspberry Pi. The vim (vi improved) editor has many fans in the Linux world. This is also included in the popular Raspberry Pi distributions. It is not, however, an easy editor for the beginner. You can run it in the same way as nano, but using the command vi instead of nano. There are more details on using vim at http://newbiedoc.sourceforge.net/text_editing/vim.html.en.