Chapter 4: Editing and viewing files

Editing files

face Robert Craven

Make sure you’re in ~/modules/shell/notes, and make an empty file, misc.txt:

username@MACHINE:notes$ touch misc.txt

To edit this file from within the terminal, we can use the program nano. This is a simple text editor designed to work using keyboard commands only—without the use of a mouse.

Although nano won’t be the main editor you use for writing code, it’s useful for quick edits to files—and very useful if you’re logged in to a machine without a graphical user interface. (For instance—typically, if you’re logged in remotely, from home.)

Let’s edit misc.txt.

username@MACHINE:notes$ nano misc.txt

You’ll see something like the following:

nano editor

You can proceed to edit the file, just as you would using any other editor.

  • To move the cursor around, use the cursor keys instead of the mouse.
  • To save the file, use Ctrl+O
  • To exit the editor, use Ctrl+X

Exercise 10

  1. Write some text in the file mist.txt, and save it.
  2. Exit nano, and view details of the file using ls -l. (Notice that the size of the file now corresponds to the amount of text you’ve saved in it.)