| UNIX Tutorial | 5. Viewing and editing files |
|
Commands covered in this section: cat, more, pico So far, we've been concentrating on copying, moving, and removing files. Now let's start looking at the contents of the files themselves. Text files can be displayed on the screen and edited. There are a number of text editing programs available for UNIX; most notable among these are vi and Emacs. However, learning to use these is beyond the scope of this tutorial. We will use pico, a simple text editor that comes with the popular Pine mail program. Before we get into editing files, let's try simply displaying the contents of a file. Exercise 5.1
Use the cat command to display the contents of
the "hosts" file copied into your "test" directory.
One problem with cat is that a file which
has more lines than your screen will simply scroll off
the screen. The more program is designed
to overcome this problem. It allows you to scroll through
the file one screen at a time.
Exercise 5.2
Use more to view the "hosts" file.
The more program is an example of a pager, a program
that allows you to page through a text file. Not surprisingly, there's
a new-and-improved pager called less. Now let's try creating and editing a file with pico. Exercise 5.3
Type "pico" followed by the name of the file you want to
create.
The pico text editor is shown in figure 5.1.
Figure 5.1 The pico text editor.
Type a few lines of text into the editor. We will use these to practice with. Editing functions in pico are invoked by pressing the Control key (marked as 'Ctrl' on most keyboards) and another key simultaneously. The bottom two lines of the editor window show a menu of editing commands ('^R', for example, signifies pressing the 'Ctrl ' and 'R' keys simultaneously). Let's try pico's primitive cut-and-paste function. Move to the second line of your text and press '^K'. The whole line should disappear. Now move to the end of your text and press '^U'. This pastes the line of text into the new location. Try searching for a word in your text with '^W'. To save your work without exiting, type '^O'. To exit, type '^X'. If you have any changes that haven't been saved, you will be prompted to do so before exiting. pico does not have many of the advanced features that other editors such as vi and Emacs have (such as search and replace), but it is easy to use and certainly adequate for editing small files. |
|
|
< previous | table of contents | next > |
|