A Quick Introduction to Unix/Editing Text

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Pico: the simplest editor[edit | edit source]

So far we have been using built-in Unix commands issued directly at the shell prompt. To take things a little further we really need to be able to create and edit text files. There are a large number of different editors available for Unix users, among them

We are going to use pico because it is very widely installed on Unix systems and is by far the easiest to use for the beginner.

Pico is a terminal based program and when you start it the terminal switches from the prompt to the pico editing screen. So, if you type

% pico

you should see


where at the bottom of the screen you see two rows of Pico command help. This on-screen help is what makes Pico attractive to beginners. Although the commands are unfamiliar (and perhaps even idiosyncratic) you have reminders always to-hand. Pico doesn't have the sophisticated text manipulation functions or flexibility that other Unix editors have, but we don't need that yet.

You can start Pico with a filename as well, typing, for example

pico firstscript.sh

Notice that I gave the file the extension .sh to remind me - and Unix - that it is a script file (of which more later). The screen will look just the same if the file doesn't exist when you start but if the file does already exist then its contents will be displayed on screen. You enter text directly at the Pico cursor and issue commands with combinations of the control key and a character (the character part is not case sensitive). If you issue a command and wish to cancel it you use ^c. You can move about your file with the arrow keys.

Pico Peculiarities[edit | edit source]

Some Pico behaviour will take a little getting used to.

Pico Command Result
^ alone begins to mark text as selected. Now move the cursor with the arrow keys and text is highlighted. The selection ends at the current cursor position.
^k cuts selected text
^u pastes the last cut
^i creates a tab/indent
^o saves the file when you have finished editing

Pico does have a little more functionality than this (although not much!) but this is enough for current purposes. Before you go on to creating scripts, use the Pico editor to create a text file of your own making sure to practise these few commands.