Unix: Editing files
You are often required to edit text files when working with your shell account.
For example, to configure where your mail is forwarded to you need to edit the
file .forward
in your home directory. To do this, you will need
to use a text editor. There are many text editors available, and most of them
are utterly cryptic and take a lifetime to learn. This page gives a quick
introduction to nano, an editor that takes minutes to master.
Using nano
Editing files with nano is as simple as typing:
nano filename
If you have ever used a simple text editor you should be pretty comfortable with nano. You move around using the arrow keys, delete stuff using backspace and insert stuff by typing.
When you are finished, press Control-X
, and you will be
asked whether you want to save the changes. Press Y
to save your
changes, N
to discard them and Control-C
to go back to
editing the file. At any time you can press Control-O
to save any
changes and carry on editing.
To delete a line of text, press Control-K
. To paste the deleted
text at the current cursor position, press Control-U
. If you
press Control-K
to delete more than one line, all the lines
deleted will be pasted.
To wrap a paragraph, press Control-J
. There are options to turn on auto-wrapping; type man nano
for details.
Other editors
Whilst nano is certainly very easy to learn, it is somewhat limited in functionality. If you are going to be doing a lot of editing on Unix, you would do well to learn one of the more fully featured text editors, such as vi, vim, joe or emacs. Unfortunately, the question of "which text editor is best" is an ongoing, vociferous and uninteresting debate. We will not expose you to our opinions unnecessarily.