UNIX Tutorial Five

5.1 Text Editing

Now that you have had the chance to generate some text files, you might be wondering how we could change the text in those files. There are several options for editing files on Unix (emacs, vi, vim, joe, OpenOffice), each designed for different kinds of computer users. On Windows we might do this with Microsoft Word, but that type of program is usually overkill for Unix because you are just trying to edit a file that is only a few lines long and you do not need fonts or any extra formatting. Some folks are aware of the NotePad program on Windows, which is a simple program that allows you to edit the contents of a file quickly. A program on Unix that functions similar to NotePad is emacs.

emacs

The emacs text editor is often called the Unix user's swiss army knife because it can do many things. In this course, you will likely just use it for text editting, because it has nice user friendly interface. Since we will be generating some new files while text editting, let's create a new directory act2 inside your groupwork directory.

% cd ~/groupworkv
% mkdir act2
% cd act2

To begin using emacs in your act2 directory, type

% emacs newfile.txt &

NOTE: the & symbol is used to run a command in the background. This means that the command prompt will return immediately after you run the program, no matter how long it takes for that command to complete. In this case, if you were to run emacs without the &, you could not run any additional comands until you exit from emacs.

After a few moments, you should see a window popup on your desktop

emacs window

This has opened a new file called newfile.txt and emacs is ready to start taking your text input. Go ahead and type

The quick brown fox
jumped over
the lazy dog.

If you make a mistake, you can use either the arrow keys or the mouse to reposition your cursor. When you have finished typing, you can save the file by clicking the File menu and then click Save (current buffer).

When you are done editting and saving the file you can exit emacs by clicking the File menu and then click Exit Emacs.

There are a number of other useful commands within these menus and you should explore them when you have time.

Exercise 5.1

Open the science.txt file in your act1 for editting, use the Search command within emacs to find the word asteroids, change it to meteoroids, and then save the editted file as science-new.txt in your act2 directory.

Summary

command & run command in the background
emacs file open a window to edit the text of file

 

M.Stonebank@surrey.ac.uk, © 9th October 2000; Revised brudzimr@muohio.edu, 19th August 2006