<=================================================================>

UNIX and EMACS Tutorial

<=================================================================>

For more help -- Go to the Ops home page for more interesting and helpful stuff.

Introduction

This guide is an introduction to using the computer network provided by the University of New Orleans Department of Computer Science. The computing facilities and staff who run them are referred to as the Operations staff (OPs). You will be using Sun Sparc based workstations, which use the UNIX operating system. If you have only used microcomputers (i.e. IBM PC's, or Apple Macintosh computers), UNIX will be very different from what you are used to. This guide will help you learn the basics of the UNIX operating system. If you are already aquainted with UNIX, you will know most of the information in this guide. However, it is still a good idea to at least skim through the whole information guide paying particular attention to the sections which cover features that are site-specific, such as the section on our printing facilities.

Introduction to the UNIX Shell.

This chapter explains some of the basic concepts you need to know in order to understand how our computing environment works.

Introduction to Window Systems and X Windows.

This chapter introduces you to basic concepts of a window system, and to the window system used in our computing environment.

UNIX: Basic Commands.

This chapter describes the basic set of UNIX commands with a particular emphasis on the commands necessary to create and manipulate files and directories.

Communicating With Other Users Under UNIX.

This chapter explains how to interact with other users on our systems and on other systems around the world using electronic mail and news.

Emacs: Editing Under UNIX.

This chapter explains how to use the Emacs text editor to manipulate and change files created using Emacs.

See OPs home page for the following topics.






Introduction to Window Systems and XWindow

As we mentioned last chapter, we use the X Window System (twm). At present, we are using version X11. Window systems have a number of common features. If you are already aquainted with another window system such as Apple's Macintosh's window system, some of this information will be familiar. However, unless you are already aquainted with twm, you should at least skim the section on the basic features of window systems, and read through the rest of this chapter. By default, the user interface is twm, however, openwindows is available if you prefer.

Common Features of Windows Systems

Using Multiple Windows

In the default environment none of the windows overlap each other. However, it is possible for two windows to overlap. When two or more windows share the same space on the screen, the windows are essentially stacked on each other. This is one of the reasons that your working environment is referred to as a desktop. A window that can still be fully seen is referred to as the front window. The window that is partially obscured is the back window. Of course, more than one window can be involved so a given window can be behind on window and in front of another. Generally, any window you can see can be pulled to the front of the screen, or pushed to the back. TWM uses the term focus to explain how it knows where input from the keyboard should go. There are two options for this: either the input should go to the window the mouse is in, or the input should go to the front window (the window at the top of the desktop) regardless of where the mouse is at the time. The default mode is unfocused, so that input goes in the window the mouse is in, even if it is not the front window.

The Anatomy of a Window

Most of the twm windows you will use have the same basic structure as the xterms and Emacs windows and consist of three or four separate areas, depending on the type of window: the body, which holds the text or items of interest; the title bar; the frame; and sometimes one or two scroll bars. While the purpose of the window's body is self-evident; the other parts of the window require some explanation.

The Title Bar

Title bars commonly have three features: the title bar itself, a close box, and a resize box. The title bar itself distinguishes the window you are working in from the other windows that are open; ie.the active window's title bar is gray where all other windows have a white title bar, also, the title bar can be used as a handle for moving the window around the desktop. Under twm, you can move a window by clicking on the title bar and holding down either the left or middle mouse button while moving the mouse. Twm also lets you pull and push a window between the front and back of the desktop by clicking in the title bar. Clicking with either the left or center mouse button on the title bar of the front-most window on the screen pushes it behind all the other windows. Clicking with those buttons on a window other than the front-most window pulls the window to the front of the screen.






Introduction to UNIX: Basic Commands

Introduction

This will acquaint you with a small subset of useful UNIX operating system commands and symbols that can be used on the ELC workstations. The purpose is to present a working set of UNIX commands for the beginning UNIX user, rather than as in-depth description of everything. There are several good books available on UNIX operating system commands.
The following is one example : Hahn, A Students Guide to UNIX

Take note that UNIX comes in several flavors, so do not expect everything you read in a UNIX book to be implemented on Sun workstation. The two flavors of UNIX currently prevalent are AT&T's System V and Berkeley BSD.

Online UNIX Help - The "man" command

Before presenting some of the basic UNIX commands, it is worth mentioning the most basic UNIX command: the man command. This command is short for "manual" and allows one to read a short message about each UNIX command available on a given computer system. For example, to learn more about the UNIX command cat, one could type:
man cat
in an xterm window.

One problem with the man command is that you must know the exact name of a command to find its corresponding manual page. For example, if you try
man copy
you will get an error message since copy is not a UNIX command. Obviously, learning the exact UNIX command name you need will be difficult. One way around this problem is to use the man command with a keyword search such as:
man -k queue
The "man" command will search for the keyword queue and will display all UNIX commands that have that keyword in their short description.

NOTE: Do not print the man pages.

Structure of the man page

The Name heading tells you which command is being described on the man page.
The Synopsis heading tells you briefly what possible switches or other information must or can be included when using the particular command.
System V Synopsis tells you what switches are peculiar to the system V version of UNIX only. You are using the Solaris flavor of UNIX which is system V.
Availability tells you to what extent (if any) a particular command is available to the system and what requirements there are for the command to be available.
Description gives a short description of what the command is supposed to do and sometimes includes examples of how to use the command.
Options gives a complete list of what switches are available for use with the command and what the switches do.
If you have questions on the use of man type :
man man
in a terminal window.
Remember that the man pages will provide you with information about particular individual commands, not with specific examples of how a command can be used in conjunction with other commands to accomplish whatever task you need to accomplish. You are encouraged and expected to learn as much as you can about the various commands (using this manual, the "man" pages, and other relevant sources) so the operators do not need to hold your hand every step of the way through your assignments... Do not, however, be afraid to ask questions. The operators are there to help you. Please be considerate, however, and do not expect operators to do the "leg work" you should be doing yourself. A properly prepared user allows the operator to get to the heart of the problem, thus freeing up time for them to spend with other users.

Introduction to the Shell

The program that accepts and executes UNIX commands is the command interpreter or shell. New accounts are set up with csh (pronounced seashell) as their default shell. One of the greatest strengths of the shell is its ability to connect different commands together. A number of UNIX commands seem to be nearly useless; however, by taking the output of one command and feeding it to another, these commands can be tied together into something quite powerful. This section will describe how the shell ties commands together.

Multitasking.

Multitasking allows you to run more than one process (or task) at a time. When you enter a command in the usual fashion, you start a process in the foreground. After starting a foreground process, you have to wait until the command terminates to execute the next command. However, running time-consuming processes (e.g., compilation of programs) in the background will allow you to execute other commands (e.g., editing a file) in the foreground at the same time.

You must pay attention to the input/output devices when submitting a background job. Redirect standard input (stdin), standard output (stdout), and standard error (stderr) to files to avoid conflicts.

Running a job in the background.

To run a command in the background append the ampersand (&) to the end of the command. For example, to run the emacs editor in the background type:
emacs &

Canceling a job.

To stop a job that is running in the background, enter the command ps. Browse through the list of jobs running and note the PID number of the you wish to stop. At the prompt enter:
kill (PID#)

Moving a job to the background.

If you have started a process in the foreground and decide to put it into the background, follow this two-step procedure:

  1. Suspend the foreground process by entering control-Z. A "stopped" message will appear on the screen, and the prompt will reappear.

  2. Enter the bg command to place the most recently stopped process into the background. A message will display the background number and the PID of the job.

NOTE: A job can also be in the "stopped" state if it is waiting for terminal input (as opposed to having been stopped with control-Z, for example). If you have stopped backgrounds jobs, you should not log out of the system without first canceling them.

Moving a job to the foreground.

You can enter the fg command to bring a background job executed during the current terminal session to the foreground. The syntax of the command is:
fg %job_number
If you do not specify a job number, the most recent background job is the default.

NOTE: You cannot move background processes executed during previous terminal sessions to the foreground.

Standard Input, Standard Output, and Standard Error

UNIX commands are commonly referred to as filters. This reflects the fact that the command takes some input and processes or filters it to produce some output. Now, if a command is supposed to use a certain input file to execute the command, and you do not specify that this is indeed the input file it should use; the command assumes it should use the standard input file (stdin). Likewise, if the command commonly produces an output to a certain file and you do not specify the file the output is supposed to go to, it puts the output in the standard output file(stdout). Further, when a command generates an error message, it will go to the screen even if the normal output for that command is supposed to go to a file. The screen is, in effect, the standard error file (stderr) where error messages are sent. Collectively, these three files are referred to as standard I/O and are sent to the xterm window by default.
For example, consider the valid UNIX command cat. Normally the cat command takes an input file and concatenates it to an output file. No files have been specified in this example, however, so cat assumes that it should concatenate the standard input file to the standard output file. Since both files are the xterm window, it means cat will read whatever is typed into the window and display it back to the window. This process will go on forever unless you stop it by typing Control-D (..end of file) at the beginning of the next line. This all may not appear very useful but in reality it is the existence of standard input and standard output that give the UNIX shell its true strength. This is what allows the shell to connect the standard output of one program to the standard input of another.

Redirection

As described above, the shell can redirect a program's standard output to a file. If you type: > filename at the end of a command, the shell will send the output of the command into the file you have indicated.
You can, for instance, create a file listing all of the files in your directory by typing:
ls > myfiles
now the file myfiles contains the output of the ls command.

If you want to add the output of a command to an existing file, use >> instead of >.

Standard error can be redirected as well. To put the standard error messages in the same file as the standard output, use >& instead of > , and >>& instead of >>.

Standard input can also be redirected. Many commands automatically check to see if the user wants to redirect to standard input so it comes from a file instead of from the terminal (for instance, cat, as mentioned above). However, for commands such as elm that cannot check for a file name, you can redirect the standard input from the terminal to a file by using <. For example:
elm smith < letter.txt
Note that the file names on either side of the < or > must be different file names.

PIPES

The UNIX shell connects one program's standard output to another program's standard input through the use of pipes. A special character (the vertical bar "|") tells the shell to connect one command's standard output to another command's standard input. For example, to list your files one page at a time, similar to the way that the more command lists the contents of long files one page at a time, use a pipe between the ls command and the more command:
ls | more
The second command can then have its standard output piped to a third command's standard input and so on.

Informative commands

Finding your current location.

Entering pwd (short for print working directory) displays the full name of your working directory. The full name of a directory is its absolute pathname.

Finding out who is logged on.

Enter rusers at the command prompt to generate a listing of the users of everyone currently logged on.

Getting more information about other users.

The finger command displays information about a specific user. For instance, entering:
finger jdoe
lists all information available on any user whose username is jdoe.

Directory and File Names Under UNIX

General

In Unix , there are two kinds of files: ordinary files and directory files.
( This is somewhat of a lie. When you take 3401 you will learn about several other special files. )

  1. Ordinary files may contain text, code for a program, or other information.

  2. Directory files are collections of directories and ordinary files. Directory files organize other files into meaningful groups.

Invisible files.

All invisible files have names that start with a "."(dot) and are also referred to as dot files. They are called invisible because they are not normally displayed in a directory listing. In other words when you issue the command ls in a UNIX shell, dot files are not displayed. To see all of your files use the -a switch:
ls -a
There are several important default invisible files in your home directory: the .(dot), ..(dot dot), .login, .cshrc, .login, and .user.interface. To name a few.

The system uses the . and .. files to connect to the current directory (.) and its parent directory (..). The .login file contains commands that UNIX will execute every time you login to your account.

Naming Conventions

Limits. File and directory names can be from 1 to 255 characters long.

Special Characters. UNIX is case sensitive, that is, Lab1 is a different name from lab1. You may use letters, digits and special characters in UNIX names. Aside from letters and digits, the hyphen (-) and the underscore (_) are the best characters to use in file names.

NOTE: DO NOT put a hyphen as the first character of a file name.(trust me !!!)

Some other characters frequently have special meanings and you should refrain from using these characters in your file names to avoid problems. A few examples of characters that have special meaning are: <, >, & and |.
White space characters should not be used. If you do use any of these characters by mistake, or if you transfer a file from another computer system that has these characters in its name, you will have problems accessing the file in the future to change or delete it. One way around this is to put single quotes around the name, or use a backlash (\) to tell the shell to ignore the special meaning of the character. For example, to remove a file named strange>name, you would need to use:

rm strange\>name

Directories. There are some standard names for UNIX directories and subdirectories based on the purpose of the directory. Directories named bin normally contain executable programs. Manual pages are stored in man directories, while other miscellaneous documentation is frequently found in a doc directory. The lib directories hold libraries of various procedures and functions that can be used when writing a program. The include directories usually have files containing special constant, function, and procedure declarations for use in C programs. Directories for storing source code are usually named src. Directories named tmp are usually for temporary storage of files.

Files. On some computer systems, the name of a file consists of two parts: the file name, which identifies the file itself, and the extension, which identifies what type of file it is. While this is not true for UNIX systems, it is a common practice to include an extension on file names. Some programs actually make use of the extensions. For example, the Emacs editor checks the extension, and can activate a special editing mode for that type of file.

Wild Card Characters. The UNIX shell supports the use of wild card characters in file and directory names. A wild card character is a character that takes the place of one or more regular characters in a file or directory name, and is used as a sort of shorthand when entering commands. The two wild card characters are the asterisk (*) and the question mark (?). The asterisk can match any number of characters, including one or none. The question mark (?) replaces any single character. For example, the filename chapter* would match files named chapter, chapter1 or chapter1-5.text. The file name chapter? would match files named chapter1 or chapterA but not chapter or chapter.1.

There are limits as to how the wild card characters can be used. You can use wild cards to specify one or more files anywhere you could specify multiple file names. For example, the "cat" command mentioned earlier can be used with multiple files:
cat file.1 file.2 file.3
so you could use a wild card there (e.g., cat file*) to more quickly execute the command.
However, if a command expects only a single file name, you cannot use a wild card.

Directory-Related Commands

Directory Shortcuts. There are four shortcuts you can use to refer to different directories:
  • Any user's home directory can be referred to as ~username, instead of /Net/cshome/home/csci/stu/username.
  • Your own home directory can be referred to as ~.
  • The directory you are currently in can be abbreviated as . (dot).
  • The directory one level up from your current directory ( the parent directory ), can be abbreviated as .. (dot-dot).

For example, if you are in a directory /Net/cshome/home/csci/class/c1583, .(dot) refers to /Net/cshome/home/csci/class/c1583,
and ..(dot-dot) refers to /Net/cshome/home/csci/class.

Creating Directories (mkdir). One of the main reasons for the structure of the UNIX file system is to let the user separate files into logical groups.

For example, you might want to create a subdirectory to hold all the files you will be using to do a particular lab. You can create directories using the mkdir command:
mkdir Lab1
will create a Lab1 subdirectory in the current directory.

Moving About (cd, pwd).

The cd (change directory) command lets you move from one directory to another.
You can move to a subdirectory of the current directory by entering cd nameofsubdirectoy

To move to your Lab1 subdirectory, enter:
cd Lab1

You can also use the directory's full pathname. For example, to move to /Net/cshome/home/csci/class/c1583, you would enter the command:
cd /Net/cshome/home/csci/class/c1583

The directory shortcuts mentioned previously can be used here; for example:
cd ~/Lab1
would take you back to your Lab1 directory and then:
cd ..
would take you back to your home directory.

You can return to your home directory from anywhere by entering:
cd
( cd by itself will take you home. )

The pwd (print working directory) command allows you to find out your current working directory simply by entering:

pwd

Listing the Contents of a Directory (ls)

The ls command enables the user to list filenames that are in the working directory. Consider the following examples:

  • ls
  • ls /usr/class/c1581
  • ls -a
  • ls -l
  • ls -al
  • ls -alF
  • ls [l-p]*

In the first example, the names of all files in the current directory that do not begin with a dot are displayed.
To list the files in some directory other than the current one, simply add the directory's name, as shown in the second example.

The next three examples illustrate the use of a switch with UNIX commands.
This is very handy and permits a single UNIX command to function as several related commands. The -a switch includes files that start with a . or dot files, as well as the rest of the files in the current directory.
The -l switch displays the same files as ls, but more information is printed about each displayed file. Both switches can be combined to produce the -al switch as in the fifth example, providing the extra information on both regular files and dot files.

In the sixth example, a third switch, -F, has been added. This uses a special character to indicate if a file is really an executable program, a symbolic link, a directory, or an ordinary file. Executables end with an *, symbolic links end with @, directories end with /.

The last example will list all files that begin with l thru p.

In the example below, Lab1, Mail, Manual and News are directories, calendar is a file, new-progis an executable program and POLICY.TXT is a linked file and cannot be altered or deleted.

% ls -lF
total 7
drwx----- 2 miked 512 JUL 10 12:50 Lab1/
-rw-r--r-- 1 miked105 JUN 22 09:31 calendar
drwx------ 2 miked512 JUN 30 09:20 Mail/
drwx------ 2 miked512 JUN 22 14:20 Manual/
drwx------ 2 miked512 JUN 22 13:04 News
-rwx------- 2 miked133 JUN 22 13:09 new-prog*
lrwxrwxrwx 1 cscistu 15 JAN 2 02:09 POLICY.TXT@ -> ../POLICY.TXT

When you try to list the contents of a directory other than your own (for example, "/Net/cshome/home/csci/class/c1583" in the e.g. above), you may not be able to see anything. Each directory has a set of permissions that control who can see or change the contents. You can change the permissions on your files and directory (but not other users' files and directories) using the chmod command (see the man chmod entry for more information). If you need to access someone else's directory or file, and you get the following message: '/Net/cshome/home/csci/class/c1583 unreadable', you do not have permission and you need to contact your instructor or the person who told you to get something from that directory or file and have them change the permission on the item you need to access. There are a number of other switches for the ls command. You should not worry about memorizing a command's switches but instead just remember that switches do exist. In case you need to know the possible switches for a command, then a reference manual of UNIX commands can be consulted or the man command can be used.

File protection

In UNIX, each file has access privileges associated with it. Only the owner of the file can change these access privileges.

Classes of access permissions - user, group, other.

Each file in the UNIX system has a code attached to it that determines who has permission to read the file, write to the file, or execute the file. Access levels are divided into three classes:

  • u The owner of the file (u is short for user).

  • g The members of your group (g is short for group).

  • o Users who are not members of the group (o is short for other).

Types of access permissions - read, write, execute, none.

Here are the types of access permissions:

     Access code       Access name      Access description
	  r            read access       view the file
          w            write access      change or delete the file
          x           execute access     run the file
          -             no access        no access

Enter the ls -l command to find out how access is currently set on your files. the information displayed for each file includes a section that lists access permissions, for example: -rwxr-xr-x.

  • The first character (-) is the type: In general, the type will be either - (dash) for an ordinary file or d for a directory. In the above illustration, the type is an ordinary file.
  • The next three characters (rwx) determine the owner's access to the file. The owner (u) in this example has read (r), write (w) and execute (x) access to the file.
  • The next three characters (r-x) determine the group's access to the file. This group (g) has been given read (r) access, denied write (w) access, and given execute (x) access to this file.
  • The last three characters (r-x) represent permissions given to all others (o). In the above case, other users have been given read (r) access, denied write (w) access, and granted execute (x) access for the file.

Changing access permissions - chmod.

Enter the chmod (short for change mode) command to change access permissions for your files. The chmod command has the following format:

chmod who[+/-]permission filename

  • who either u for owner, g for group, o for other users (outside of group), or all (u, g, and o)
  • [+/-] add or subtract permission
  • permission r for read access, w for write access, or x for execute access
  • filename the name of your file or directory

Enter the ls -l command to verify that the access codes have changed to your preference.

You may specify multiple permission codes in the chmod command line. For instance, issuing the command:

chmod go+wx test

will provide the group and other users with write and execute access to the file or directory named test.

Another example involving removing permissions:

the access code for a file called test.c might be: -rwxrwxr--

To remove write access from the group, enter the command:

chmod g-w test.c

This will result in the following access code for test.c: -rwxr-xr--

Moving and Renaming Directories (mv)

The mv command will let you move directories and subdirectories, or rename them.

You can move a directory into another directory by entering:
mv directorytobemoved newparentdirectory

You can change the name of a directory by entering:

mv oldname newname

Finally, you can combine the two:

mv oldname newdirectory/newname

NOTE: No two items (files and/or directories) can have the same name at the same level. (ie. you can't have a directory and a file named foo in your home directory.)

Removing Directories (rmdir, rm -r)

The rmdir command removes an empty subdirectory. To remove a subdirectory, you can simply enter:
rmdir
nameofdirectory

Naturally, this assumes that you are in the parent directory of the subdirectory; if you are not, then you have to specify an appropriate path. This command works only if the subdirectory has no files.

If a directory still has files in it, you can get rid of the files by using:
rm -r nameofdirectory

which will remove all files and directories in nameofdirectory, and then will remove the nameofdirectory directory itself.

NOTE: Be very careful when using rm -r.
On UNIX, once files and directories have been removed they cannot be recovered. However, by default, you will be asked to confim each deletion.

Home directory.

When you first login to your UNIX account, you will be in your home directory. This directory belongs to you, and you control the files and subdirectories created and stored here.

Working directory.

The working directory is the directory in which you are currently doing work. When you login, your home directory will be your working directory. If you change directories, then the directory into which you have moved becomes your working directory. See pwd.

File-Related commands

Creating Files

The most common method for creating files is to use an editor. Your account is set up to use Emacs as the default editor. Other editors are available; the second-most commonly used editor is vi.

You can create files without using an editor by using the cat > filename command. For example:

aquarius[~]{20}->cat > new.file
Now is the time for all good men to come to the aid
of their country.
^D

The example above would create a file new.file with that sentence in it. ^D stands for the key sequence control-d which signifies end of file in UNIX. In other words, after having typed the last line (and hit the return key), you hold down the control-key and press the D-key at the same time.
This use of cat can be useful, particularly if you want to create a one or two line file.

Appending to Existing Files

Again, for large amounts of information, especially if it has to be entered by hand, you should use your editor of choice. However, cat > > will let you append information to an existing file. See also Redirection.

Copying Files (cp)

The copy command cp can be used to make a copy of a file either in the same directory or to another.

Let us assume that in our current example that we wish to copy a file or files from subdirectory Lab1 to subdirectory Lab2 .
If the current directory is Lab1, then the command:

cp lab1.mod ~/Lab2/lab2.mod
would make a copy of lab1.mod in Lab2, and would rename it lab2.mod.

If you did not want to change the name of the file, simply enter:

cp lab1.mod ~/Lab2. (the period after Lab2 is important)
This puts a copy of lab1.mod into the Lab2 directory , but retains the name lab1.mod.

For more details on cp, enter the command:

man cp

Moving and Renaming Files (mv)

The section above explains to use the mv command to move or rename directories. The command can also be used to move or rename files. The mv command works in the same way for files as it did for directories. You change the name of a file by entering mv oldfilename newfilename. You move a file to another directory by entering mv filename newdirectory. You can move several files simultaneously by entering mv filename.1 filename.2 newdirectory.

Finally, you can rename a file and move it to another directory at the same time by entering mv oldfilename newdirectory/newfilename.

Displaying Entire Files(cat, more, less, xless)

There are several commands that display the contents of files: cat, more, less and xless. These commands allow one to display the contents of a file in the terminal window in several convenient ways. You are very strongly encouraged to use these commands to preview long files before you print them out in order to save time and paper. The cat command will display a file on the terminal window without pausing. If your file is too long to fit in your terminal window it will fly by until the end of the file is displayed. You can use the scroll bar on the right of the terminal window to scroll backwards. In practice, cat is used to display short files and more is preferred for longer files. The command more lab1.1st displays the first screen's worth of the contents of "lab1.1st" in your terminal window. "--More-- (_%) is displayed at the bottom of the window. There are four ways to respond:

space barTo scroll to the next page.

returnTo scroll to the next line.

bTo scroll back one page.

qTo quit displaying the file and return to the UNIX prompt.

Less is an advanced version of more. In addition to the four commands mentioned above, less adds:

yTo scroll back one line.

gJump back to the start of the file.

GJump to the end of the file.

Both more and less offer the ability to search for words in the file. Check the man pages(man more and man less) for more details. The display command xless has been designed especially for the X window system. When you enter xless filename, you will get a "new window" mouse prompt. An outline of the new window will appear. Moving the mouse will move the outline; clicking the left mouse button will replace the outline with the actual window. The xless window gives you both horizontal and vertical scroll bars which allow you to move through the file. Clicking the mouse on the "quit" button closes the xless window, and returns control to your terminal window.

Displaying Part of a File (head, tail)

There are two commands that can be used to display part of a file: tail and head. The tail command displays the last ten lines of a file. The head command displays the first ten lines of a file, tail makes it easy to look at just the end of an output file to see how far a program executed. It is also useful for looking at program listing files when the compiler puts the syntax errors at the end of the listing. Head can be helpful if you want to confirm that the contents of a file are what you think they are, by showing you the first few lines. For both commands you may use a switch to specify the number of lines displayed:

tail -25 lab.1st

head -100 lab1.mod

tail +100 lab1.mod

In the first example, the last 25 lines will be displayed. In the second, the first one hundred lines are displayed. In the last example, all but the first 100 lines will be displayed.

Deleting Files (rm)

In your programming work, there will be times that you will want to delete files from your directories. Files that can be recreated easily (the output from your lab programs, the intermediate files created as your lab compiles, the executable files, etc.) should be deleted once you have completed the lab they are associated with. If you know that you will not need the information in the file again, you should delete it. Certain programs leave a copy of the original file "foo.txt~", as well as an auto-save"#foo.txt#". The rm command removes files. You can use rm to remove a single file, several specific files, or all files matching a particular pattern. As noted before, rm -r removes a directory, and all of it's contents.

FILES TO DELETECOMMAND

Single file rm filename

Several different files rm filename1 filename2 etc.

Several similar files rm *.txt

The rm command does not automatically delete the files it is told to delete. Instead, each of the filenames will be displayed on the screen and you will be given a chance not to delete them.

aquarius[~/Mail ]{103}-&gtrm *

rm: remove francis? y

rm: remove grichard? y

rm: remove received? n

aquarius[~/Mail ]{104}-&gt

In the example above the user has told the computer to delete all files in the Mail directory. Instead of simply deleting the files, the computer asks the user to confirm the deletions. The user has said not to delete "received", and to go ahead and delete the files "francis", and "grichard". This confirmation process helps to protect you from accidentally deleting the wrong files. If you have deleted all the files you wanted to and rm is still asking you whether of not it should delete other files, simply type control-c instead of an n. The current file, and any others rm would have asked you about will be left alone.

Printer-Related commands

Printing Files (lp)

To get a printout of a file, use the lp command. Do not try to print binary files (like any file ending in a ".o", ".ali", a compiled program, etc.). These files cannot be printed.

Removing Print Jobs (lpc status, lprm)

When the labs are extremely busy, there can be a number of people who are all waiting for printouts. The lpc status command lets you see how many print jobs there are ahead of yours and how large they are. Like lp, lpc status returns information on the printer queue for your default printer. If you have accidentally printed out a file that you did not mean to, or printed the same file twice, you can remove that print job from the printer queue with the lprm command. You need to run lpq before you run lprm. lprm requires that you specify the number of the print job you want canceled, and lpq provides that information. Your printed file can then be picked up, at the counter, in room 320. If you are mistakenly given someone elses printout, return it to room 320. Remember that printing costs real money. You should make every effort to minimize the number of pages you print. Never print the output files from your labs without checking their contents first.

Customizing your environment

Aliases

Aliases are abbreviations for commands or sets of commands. This feature is particularly useful to execute commands of command sequences that you use frequently. In this way you can avoid retyping a command sequence many time during a login session. To display the aliases currently in effect, issue the command alias:

aquarius[~ ]{122}->alias

To define new aliases, enter the command alias mnemonic 'command' where mnemonic is the name of the alias and command is either a command, a command pipe, or a combination of these separated by semicolons. Examples of valid definitions:

alias h 'history'
Entering h will execute the history command.

alias dir 'pwd; ls'
Entering dir will print the current path and show a directory listing.

Enter the following command to delete an alias definition:

aquarius[~ ]{122}->unalias mnemonic

For example, to delete the previous alias definitions issue the commands:

unalias h

unalias dir

History.

UNIX contains a feature called the history mechanism that makes it easy to repeat commands that you executed earlier in the current session. The system keeps a list of every command you enter at the prompt during your current session. By default, history is already aliased to be "h". You can list your command history on the terminal screen by entering history at the command prompt.. It lists event numbers in front of each command. A partial display of a history list might be: 1 ls -l
2 cd reports
3 lp week_12
4 h

The history mechanism allows you to repeat a command by entering an exclamation point(!) followed by a command identifier, such as the event number or portion of the command name:
aquarius[~ ]{5}->!n
where n is the command number to be executed.

aquarius[~ ]{5}->!string
where string is the command name or initial part of the command name.

The ! signals the shell that you are searching for command in the history list. Using the above illustration, you can execute the cd command by entering either of the following forms:
aquarius[~ ]{6}->!2
aquarius[~ ]{7}->!c

To repeat the last command executed, enter the command:
aquarius[~ ]{8}->!!

Emacs: Editing under UNIX

There are two main UNIX editors: vi and Emacs. The default editor for new users is Emacs. If you are already familiar with vi, feel free to use that instead of Emacs. If you are not familiar with either, you should use Emacs. The basics of vi are covered in a short subject. The rest of this chapter explains how to use Emacs in detail.
Note: that there are two flavors of emacs you can use: "emacs" or "xemacs".
Simply type the command:
aquarius[~ ]{34}->emacs &
or
aquarius[~ ]{35}->xemacs &

Introduction to Emacs

The editor you will be using is called Emacs. It is an advanced, self-documenting real-time display editor. We say that Emacs is a real-time display editor because the text being edited is visible on the screen and is updated automatically as you type your commands. Emacs is advanced because it provides facilities beyond simple insertion and deletion, such as: automatic indentation of programs; viewing two or more files at once; and dealing in terms of characters, words, lines, sentences and regions. Self-documenting refers to the fact that at any time you can bring up documentation of Emacs from within Emacs, simply by typing the character control-h twice.(Hold the "control" key down while typing the "h" !)
This will list the Emacs commands you can use at present, and it also describes what each Emacs commands does.

Using Emacs on the SUN's (room 322)

Using Emacs Elsewhere

Some of the commands described in this document may be unique to the local installation of Emacs. If you have used Emacs somewhere else, some of the commands may not work here; Similarly, some of the commands you learn here may not work elsewhere.

Character, Keys, and Commands

In Emacs, you can enter any of the 128 ASCII characters into a file. This is usually done by typing the appropriate character on the keyboard. We will refer to certain special keys by the following notation: Commands to Emacs are entered by typing CONTROL and META-characters. A control character is entered by holding down the CONTROL key at the same time a character is typed. For example, to enter the command indicated by "CONTROL-L," (view lossage) hold down the CONTROL key while typing `l'. It does not matter if you type a lower case or upper case `l', it is interpreted the same by Emacs. As a matter of convention, control characters are described as C-l, where `l' is the lower case letter. A meta-character is also entered by combining two keys. You can enter a meta-character in one of two ways:

*On any keyboards (including the Sun) you can transmit a meta-character by typing the ESCAPE key, then typing the desired character. For example, type ESCAPE and then an `x' to get the "Meta-x" character.

*On most Sun workstations, you can use the keys marked with a diamond to either side of the space bar as a Meta-key. Hold down a DIAMOND and type an x to get the "Meta-x" character.

Again, following convention we will refer to a meta-character as M-l, where l is the lower case letter. Since the Diamond key is only available on some keyboards, we recommend you use the first method described above. That method should work, regardless of the keyboard you are using. Control and meta-characters are interpreted by Emacs commands for it to perform some editing function on your file. Much of this chapter describes what those commands do. Sometimes it is necessary to insert a control character into a file. If you just type the control character while you are typing text, Emacs will try to interpret it as a command. There is a special Emacs command, C-q, that lets you quote a control character. Entering C-q C-l would put ^L (an alternate representation of C-l) into your file. As with many of the Emacs commands, the purpose of the command can be used as a mnemonic device to help you remember the letter used to enter the command (in this case, a "q"). The control and meta-commands we will be describing are really shortcuts for longer "Meta-x" commands; for example, C-q is a shortcut for M-x quoted insert. In most cases, we will only list the short form of a command. Many Emacs commands do not have shortcuts.

Getting Help

If you get into trouble while using Emacs and do not know what to do or not understand a message, you can always type C-g. This is the quit command and tells Emacs to abandon whatever it is trying to do. Emacs is an extremely powerful editor and has many more commands than will be discussed here. If you should accidentally type one of those commands, you may get prompted for more input. Just type C-g and continue. If a command you have executed has an effect you did not expect, you can use the undo command (C-x u or C-Delete) to reverse that effect. Emacs also has a built-in help facility. Typing C-h C-h shifts you into help mode. Typing C-h a third time explains the various options available to you directly into that option. Some of the help options are described in table 6.1.

HELP OPTION DESCRIPTION

a (Command Apropos) Enter a substring of a command name, and see a list of commands that contain that substring. b (Describe Key Bindings) Displays a list of all the shortcuts for Emacs commands

c (Describe Key Briefly) Enter a command shortcut, and see the name of the command.

k (Describe key) Enter a command shortcut, and see the full documentation for that command.

t (Help With Tutorial) Starts an Emacs tutorial session.

w (Where Is...) Enter an Emacs command, and see the command shortcut (if any).

If you want to perform some function, but do not know the Emacs command, use the apropos command: type C-h a, followed by a keyword that describes the function you are trying to perform. For example, say you need to convert some upper case text to lower case. The command C-h a case will create a help window and display all commands with the word "case" in their descriptions. There is an on-line tutorial in Emacs that you may use by typing C-h t. This brings up a special tutorial file that you can edit to get some practice using the basic Emacs commands.

The Organization of the Emacs Window

An Emacs window is automatically created for you when you log in. Emacs divides this window into several areas which contain their own sort of information. The biggest area is the one in which you usually see the text you are editing.

Text Windows and Buffers

While Emacs is running in a single X window, it can split this window into several "virtual windows." Initially there is one text window occupying all but the last line, plus the special echo area or minibuffer in the last line. The text window can be subdivided into multiple text windows, each of which can be used for a different file. The bottom line of each text window is the mode line which describes what is going on in that text window. It is in reverse video and normally starts with the message -----Emacs: filename. Its purpose is to indicate what buffer is being edited. Each time you visit a file, a buffer is created to hold the file's text. The name of the buffer is just the name of the file.

The Mode Line

The mode line associated with each text window displays the following information:

* Modification status- When a file is first opened under Emacs, the mode line will start with five hyphens (-----). This indicates that the file has not been modified. When a file is modified, this changes to --**-. If a file's permissions are set so that the file is read-only, the mode line will start with --%%-, since the file cannot be changed.

* Buffer name- Next, the mode line displays Emacs: buffer name. As noted above, this will normally be the file name.

* Emacs modes- The current major mode and minor Emacs modes are displayed in parentheses on the left side of the mode line. Emacs modes are discussed in Section 6.23

All- If the entire file is visible. Top- If the top lines of the file are visible. Bot- If the bottom lines of the file are visible. XX%-If only part of the file is visible, where XX is the percentage of the file which is above the top line displayed in the buffer.

The Echo Area

The line at the bottom of the Emacs window is used to echo partial commands, and to display warning messages. Echoing means printing the characters that you type. Emacs never echoes single-character commands, and multi-character commands are echoed only if you pause while typing. As soon as you pause for more than a second in the middle of a command, all the characters of the command so far are echoed. This is intended to prompt you for the rest of the command. Once echoing has started, the rest of the command is echoed immediately when you type it. In this way, Emacs can give confident users fast response and hesitant users maximum feedback. If a command cannot be executed, it may print an error message in the echo area. Error messages may be accompanied by a beep. Any input you have typed that has not been displayed yet is thrown away when an error happens. Some commands print informative messages in the echo area. These messages look like error messages but they do not beep and input is thrown away. For example, the command C-x C-s saves the current file. Since the command does not affect the file being edited, you will not see any changes in the text window. Instead, a message indicating that the file has been saved is displayed in the echo area. Certain commands require additional input from the user. For example, the command to visit another to edit, C-x C-f, needs the path and the filename of the file you want to edit. When you enter C-x C-f, the words "Find file: " and the pathname for the file you are editing show up in the echo area. When you type in the path and name of the file you want to edit, you are actually typing in a special text window called the minibuffer. The minibuffer always displays its contents in the echo area. When the minibuffer is in use, the echo area begins with a prompt string that usually ends with a colon. Also, the cursor appears in that line because it is the selected text window. You may use other Emacs editing commands while in the minibuffer (for instance, to move the point). You can always get out of the minibuffer by typing C-g.

Point, Mark and Region

When you move the mouse arrow into the Emacs window, the terminal's cursor shows the location at which editing commands will take effect. This location is called the point. Other commands move the point through the text, so that you can edit at different places in it. While the cursor appears to point at a character, the point should be thought of as between two characters. It points before the character that the cursor appears on top of. Sometimes we speak of the cursor when we mean the point, or speak of commands that move the point as cursor motion commands. A related Emacs concept is the mark . There are many Emacs commands that operate on an arbitrary contiguous part of the current buffer. To specify the text for such a command to operate on, you set the mark at one end and the point at the other. the text between the point and the mark is called the region. To select a region, click and hold the left mouse button on the character that starts the region, and move the mouse to the last character in the region. The region should be highlighted until you release the mouse button. Occasionally, you may find that the region does not quite match what you selected. Normally, this results from moving the mouse slightly just before releasing the mouse button. Try selecting the region again. You can also select a region by moving the text cursor to one end of the region, typing C-@, and moving the text cursor to the end of the region. C-@ sets the mark to be where the point is when the command is issued. If your region does not fit into your Emacs window, you will need to use this method to select it.

Entering and Exiting Emacs

You enter and exit the Emacs window by using the mouse arrow. When the mouse arrow is inside the Emacs window, characters you type will be input to Emacs. When the mouse is moved back out of the window, your input will stop going there. Be aware that leaving the Emacs window does not save the file that was edited. You must do that with the C-x C-s command. You can leave your Emacs window open as long as you like, and can return to continue editing the current file or begin editing a new file. You can get rid of your Emacs window altogether by using the C-x C-c (or close) command. The close command will ask you if you want to save any changes to the file you were editing if you forgot to save it first. You will not normally want to get out of Emacs altogether until you are ready to log out. If you enter the close command by accident, you can create a new Emacs window by typing emacs in an xterm window.

Editing Files With Emacs

You can use Emacs both to edit existing files or create new ones. Emacs automatically helps you avoid losing old information by saving the previous version of a file when you start to edit it.

Editing a New File

To create a new file with Emacs, enter the Emacs screen and type C-x C-f to visit the file. If you are already editing a file, then save the changes to that file before trying to create the new one. In the echo area you will be prompted for the file name. Note that a partial pathname may be displayed. If this is the pathname you want, complete the pathname by typing the name of the file you want to create. If the partial pathname is not what you desire, use the DELETE key to make corrections. Emacs cursor control commands may be used to edit the pathname until it is correct. Emacs looks for the file you have specified. Since it is a new file, the name does not exist and Emacs will display a "New File" message in the echo area and display an empty buffer in the text window. The point should be at the upper left corner of the text window. You can now enter text into the file by typing it. To save the file, type C-x C-s. The file will be saved under the name you entered for it.

Editing an Existing File

To edit an exiting file, again type C-x C-f (after saving any changes made to whatever file you may already be editing). As before, Emacs will prompt you in the minibuffer with a partial pathname which you may either complete or correct. Emacs will look for the file, and read it into the buffer. You can now begin editing the file. If you incorrectly type the filename, you will either get the wrong file, or you will get an empty buffer since Emacs will assume it is a file you want to create. In either case, just re-enter C-x C-f with the correct file name. Again, after you finish editing, save the file with C-x C-s. This will save it with its original name. Sometimes you do not want to save the file with its original name. For example, if you have made extensive changes to a file, you might want to save the changed version under another name, and keep the old version under its old name. Do this with C-x C-w (for write file). Emacs will prompt you for a file name, save the changed file under that name, and make that new file available for editing in your Emacs window.

Backup Files

Assume that you have been editing a file named "sample.file". If you were to move back over to an xterm window and display "sample.file", it would look like it did the last time you saved it in your Emacs window. You might also notice that a "sample.file~" is now in your directory. This is a back up file created automatically by Emacs before any of your changes were made. This is a file you can go back to if something should happen to "sample.file", or if you made a large number of unintended changes and would like to start over. Occasionally, you may see a file "#sample.file#" in your directory. This is an autosave file created by Emacs. Once you have saved your file, the auto-save file is not longer needed and will be discarded. If you have exited Emacs without saving the changes to a file, the auto-save file, if one was made, will stay in your directory. This can be very helpful if, for instance, your ELC workstation crashes before you save a file. When you see an auto-save file in your directory, check it to make sure that it is not more current than the file itself. If the file is up-to-date, you can safely remove the auto-save file. Emacs will notice if you have got an auto-save file, and will suggest that you use the M-x recover file command to get it back. Again, if the file is more current than the auto-save file, just get rid of the auto-save file. Otherwise, use the mv command or Emacs' M-x recover file command to replace the out-of-date file with the auto-save file.

Moving Around the File

Emacs has commands that move the cursor one character in any direction., These commands are mnemonic, that is the letter of the command reminds you of the function it performs. Note that all these commands merely move the cursor without affecting the text. the commands are:

C-b Back one space.

C-f Forward one space.

C-n Next line.

C-p Previous line.

Emacs also understands the concept of words, sentences and lines. The commands to move the cursor in these larger units are:

M-f Forward one word.

M-b Backward one word.

M-e Go to the end of the current sentence.

M-a Go to the beginning of the current sentence.

C-e Go to the end of the current line.

C-a Go to the beginning of the current line.

There are several commands to move the cursor by large amounts. For example, to scroll forward or backward within the window:

C-v Scroll forward one screen.

M-v Scroll backward one screen.

If you know the position of the line you want to go to, you can go there using the following commands:

M-# n Position cursor on line n.

M-&lt Go to the beginning of a file.

M-&gt Go to the end of a file.

Finally, clicking the mouse anyplace in the text window moves the cursor to that location.

Deleting Things

Deleting Small Amounts of Text

There are two ways to delete a single character: DELETE deletes the character before the point; C-d deletes the character after the point. Recall that the point is actually between two characters, although on the screen the cursor looks like it is on top of a character. The DELETE key has the effect of deleting the character before the cursor. The C-d command deletes the character the cursor is upon. You can also delete or kill text in the larger units of words, sentences and lines with the following commands:

M-Delete Kills the word before the point.

M-d Kills the word after the point.

C-k Kills the rest of the line.

M-k Kills the rest of the sentence.

Note that to kill an entire line you must be sure the point is at the beginning of the line. Use C-a C-k. Note also that when text is killed in units larger than a character it is saved by Emacs in the kill-ring. the contents of the kill-ring can be retrieved later by other commands. This protects you when unintentionally delete text. To yank text back from the kill-ring use: C-y to yank the last thing killed; and M-y to yank earlier kills.

Deleting Large Amounts of Text

The easiest way of deleting large amounts of text is to define the text to be deleted as a region. You can create a region either by setting the mark and the point, or by selecting it with the mouse. Next, use the wipe region command, C-w, to make the region disappear. Recall that it is really put in the kill-ring and can be retrieved with a C-y if you decide that you really did not want to delete it.

Adding Text

The simplest way of adding text to a file is to move the mouse cursor where you want the new text, click the mouse button, and begin typing. Note that the new text is actually entered before the current position of the point. When you want to insert a new line of text before an existing line, you can do it by positioning the point at the beginning of the old line and typing the new line of text, followed by RETURN. However, it may be easier to see what you are doing if you first make a blank line and then insert the desired text into it. This is easy to do by using the open line command, C-o. This command inserts a new line after the point, leaving the point inform of the new line. You can now just type int the text for the new line. The Emacs window you will be using assumes that lines are eighty characters long. If you type too many characters on a line, all characters are entered in the file as one line, but are displayed across the text window on two or more eighty character lines. You can tell that this has happened if a line ends with a wrap-around arrow. This signifies that the following line is actually a continuation of the line above it. Since statements in the programming languages you are using may be entered on more than one line, you should avoid creating lines greater then eighty characters long. If you would like to insert text from another file, type C-x i. You will be prompted for a filename. That file will be inserted at the point.

Undoing Changes

Emacs allows all changes make in the text of a buffer to be undone, up to a certain amount of changed characters (8000 characters). The command to undo a change is C-x u. The first time you give this command, it undoes the last change. The point moves to the text affected by the undo, so you can see what was undone. Consecutive repetitions of the C-x u command undo earlier and earlier changes, back to the limit of what Emacs has recorded. If all recorded changes have been undone, the undo command prints an error message and does nothing. Any command other than an undo command breaks the sequence of undo commands. Starting at this moment, the previous undo commands are considered ordinary changes that can themselves be undone.

Repeating Commands

To execute a command more than once, use the M-number command. This command executes whatever command comes after it number times. For example, if you want to move five lines down in the text, type M-5 C-n. This executes the next-line command five times.

Searching

Like other editors, Emacs has commands that search for occurrences of a string. The principle search command is unusual in that it is incremental. When you type the first character of your search string, Emacs will find that letter. Emacs updates its search with each new letter you type. There are also non-incremental search commands more like those of other editors. The Emacs search commands are:

C-s ESCAPE string RETURN searches for string.

C-r ESCAPE string RETURN searches backwards for string.

C-s An incremental search forward.

C-r An incremental search backward.

The first two commands are for no-incremental searches. Each command begins at the point and searches for the first occurrence of the given string, either forward or backward. Note that no searching is done until you have typed the entire string and RETURN. If that string does not exist in the file, an error message is displayed and the point is not move. If the word is found, the point is moved. It goes to the character after the word in a forward search, and the first character of the word in a backward search. The last two commands begin incremental searches.

Now start typing the string you want to search for. As soon as you enter a character, Emacs will move the point to the next occurrence of the partial string you have entered. If it is not the string you are looking for, continue to enter more characters. If you make a mistake in entering a character, use DELETE to cancel the last character in the string. When you find the string you are looking for, you can exit the search by typing ESCAPE. You can also exit the search by entering a command that is not meaningful in searches. For example, entering C-a would put you at the beginning of the line where the search string was found. If you have found the first occurrence of the string you were looking for, but want to find another one, type another C-s instead of ESCAPE. This second C-s means tells Emacs to search again. If you have already exited the search you can repeat it without retrying The C-g command does special things during searches. What it does depends on the status of the search. If the search has found what you have specified and is waiting for input, C-g cancels the entire search. The cursor moves back to where you started the search. If a C-g is typed when there are characters in the search string that have not been found, those characters are discarded. With them gone, the search is now successful and waiting for more input. A second C-g will now cancel the entire search. Note that C-r starts an incremental search backwards from the point. It works in a manner analogous to C-s.

Replacing Text

There are two types of global search-and-replace commands in Emacs. The first is an unconditional replacement command. That is, all occurrences of some old string will be replaced by a specified new string. Replacement always begins at the point and goes forward. The second type of global replace is called query-replace. In this command, Emacs searches for the string you want to replace, positions the point to the next occurrence of that string, and waits for you to tell it to replace it or not. It then continues this search and query pattern. The format of these commands is:

M-&amp "oldstring" RETURN "newstring" RETURN.

M-% "oldstring" RETURN "newstring" RETURN.

The first command above is the unconditional replacement command. Emacs takes everything you type until the next RETURN as the oldstring it will search for. Every thing before the last RETURN is taken as the new string. The second command is the query replacement command. Entering the search and replace string is the same as the unconditional replacement command. Emacs will pause at the next occurrence of the oldstring and wait for you to type in something that tells it what to do. The available commands are shown below.

SPACE, y To replace oldstring with newstring.

DELETE, n To skip to the next occurrence without replacing this one.

ESCAPE To exit without any more replacements.

. (Period) To replace this occurrence and then exit.

^ To go back to the location of the previous occurrence if you changed it.

! To replace all remaining occurrences without asking again.

You will get the message "Done" when all occurrences have been queried.

Moving Text

In Emacs, text is moved (cut and pasted) by killing it, moving the cursor to the new position, and yanking the killed text. Kill the text to be moved using one of the kill commands mentioned earlier: M-d (kill word), C-k (kill rest of line), M-k (kill rest of sentence), or C-w (wipe region). Then move the point to the place in the file where you want to insert the killed text, and type C-y (yank last kill).

Copying Text

Copying text is done in a manner analogous to moving text that has been defined as a region. First define the text to be copied as a region by setting the mark and the point. Then type M-w to save the region as the last killed, without actually killing it (copy-region-as-kill). You can now position the cursor to the desired place and type C-y to yank the copied text into the new place. You can also copy text using the "kill text" commands described in the previous section. Simply kill the text you want to copy, yank it back in the same position with C-y, move the point to the place where you want the copy to go, and yank the text back again.

Changing Case

There are several commands that allow you to change words and regions from upper to lower case, lower to upper case, or to capitalize words (first letter upper case, the rest lower).

M-l Convert following word to lower case.

M-u Convert following word to upper case.

M-c Capitalize the following word.

C-x C-l Convert region to lower case.

C-xC-u Convert region to upper case.

The first three commands only change the portion of the current word that comes after the point. The last two commands only change the text within the region.

Checking Your Spelling

The command M-x ispell buffer will check for misspelled words in your current file. The spell-checking program will list the commands you can use in the minibuffer. When it finds a word it does not recognize, it looks for words that meet one of the following criteria: (see top of next page.)

* Words that match the unrecognized word if you remove one letter. For example, "gin" or "gig" for "ging."

* Words that match the unrecognized word if you change one letter. For example, "wing" or "gong" for "ging."

* Words that match the unrecognized word if you add one letter. For example, "going" or "aging" for "ging."

The words suggested by ispell are listed in a special minibuffer at the top of your Emacs window. Each word is paired with a character. Entering that character changes the unrecognized word to the one ispell suggested. The spell-checker also allows the following special commands.

COMMAND DESCRIPTION

aAdd the current word to your personal dictionary.

cThe word is corrected but not added to your dictionary and is ignored if it appears later in this Emacs session.

rReplace this word with another. The incorrectly spelled word is copied to the minibuffer, so you can edit it.

s, SPACE, RETURN Skip this word. Do not change the word here, but do not ignore it if it appears later in this Emacs session.

?Minimal help on using the spelling checker.

C-g Quit ispell.

Multiple Windows

You can have several different files open for editing in a single Emacs session at the same time. When you open a file using the visit file command (C-x C-v), the file you open replaces whatever file might already be using the current buffer. However, there is an alternate command to open a file called the find file command (C-x C-f). When you open a file with this command, Emacs creates a new buffer for the new file, while retaining the current file in its buffer. If you only have two buffers, you can move from one to the other with the C-x b command. If you have more than two buffers, you can access and buffer by bringing up a buffer menu. Click and hold the left mouse button on your Emacs window. A list of available buffers will appear on your screen, with the current buffer directly under the mouse cursor, and highlighted with a rectangle. To select another buffer, move the mouse cursor so that the other buffer's name is highlighted, and release the mouse button. It is possible to split the text window into two (or more) text windows. Each of these text windows may be displaying a different buffer (file). Note that each of the text windows will have its' own mode line, but that the echo area is shared by all the text windows. You can use multiple text windows to edit two (or more) files at the same time. The Emacs window commands are:

C-x 2 Split the current text window into two text windows.

C-x 0 Get rid of the current text window.

C-x 1 Get rid of all the windows except the current one.

The last command is the most important for you to know, since using multiple text windows is not recommended. However, it is possible that you will accidentally create multiple windows. To get rid of them, first move the mouse arrow to the text window you want. Click the mouse to move the cursor into that window, making it the current text window, and then type C-x 1 to remove all the other text windows. In general, we recommend that you use one text window, and one buffer; this forces you to save changes to one file before editing another.

Using the Mouse with Emacs

The table below describes how the mouse buttons are mapped to Emacs functions.

KEYBUTTONACTION

Unshifted left Put point here.

middle Paste contents of X cut buffer. right Emacs menus.

Control left None.

middle Cut region to X cut buffer. rightSplit text window into two text windows.

Shift left None.

middle Put mark here. right Paste X cut buffer here.

Control-Shift left Menu of Buffers. middle Select a region with one end at the current mark. right Make two or more Emacs text windows into one.

Using the Right Keypad

On the right hand side of the keyboard are a set of keys that resemble the keypad of a hand-held calculator. This is called the numeric keypad. If you look at the front faces of the numeric keypad instead of the topfaces that you would normally look at, you will see that some of the keys are marked as R1 through R15. For the convenience of Emacs users, these keys have been bound to common Emacs commands. Pressing the key is equivalent to entering that Emacs command. The table below lists each key and the Emacs command it performs. THIS TABLE DOES NOT APPLY IF YOU ARE REMOTELY LOGGED IN TO A ELC WORKSTATION. (Disclaimer: The key labels may not work depending on whether you are using emacs, xemacs, lemacs, and also may depend on the specific workstation you are on).

KEY LABELDESCRIPTIONEMACS COMMAND

R1Go to line #.C-c C-l

R2Go to column #.C-c C-c

R3Go to beginning of line. C-a

R4Find file.C-x C-f

R5Save file.C-x C-s

R6Go to end of line. C-e

R7Go to beginning of file. M-&lt

R8Previous screen.C-p

R9Up screen.M-v

R10Back one character. C-b

R11Set mark.C-@

R12Right one character. C-f

R13Go to end of file. M-&gt

R14Go to next line. C-n

R15Go to next screen. C-v

Major Modes

Emacs has many different menu modes, each of which customizes Emacs for editing text of a particular sort. Emacs determines which mode to use based on the file name. In general, an extension to the file name determines what mode will be used when you edit that file. On the next page is a list of some of Emacs' major modes and the filename extensions that activate them.

FILENAME EXTENSIONMODE

.ads, .adbAda

.c, .h, .y, .cppC, objective C, C++

.cob, .lstCOBOL

.elEmacs Lisp

.fFortran

.sty, .bblLATEX

.l, .lisp, .lsp, .mlLisp

.mod, .m2, .defModula-2

.[1-8], .man, .me, .mm,nroff

.mr, .ms .pas, .pPascal

.PS, .psPostscript

.pl, .prologProlog

.scm, .scm. [0-9]*Scheme

.text, .TeXTeX, LATEX .texinfoTeXinfo

.text, .bib, .article, .letterText

.Z, .gz, .zipCompressed files

LATEX, nroff, and TeX are text formatting programs. The .Z mode handles files that have been compressed with the compress program, .gz mode handles files that have been compressed with gzip and .zip files have been compressed using zip. Text mode is for editing ordinary text files. The other modes are for various programming languages. Many of the modes available have special, mode-specific commands. The command M-x describe-mode lists the special commands available for your current mode. If Emacs does not know of a special mode for a particular file, that file will be opened in fundamental mode. Fundamental mode makes no assumptions as to how a file should be formatted, and provides none of the special commands available in the other modes.

Compression/ Archiving (tar, compress, gzip)

As mentioned above files can be compressed into a single file. The purpose of this is to save disk space and to organize files that are not used often (for example, last semesters files). Use tar if you wish to archive old files. For exampe, if you wish to archive all the files in your ~/class/c1581 directory the command would be : tar cvf 1581.tar ~/class/c1581/*. To restore the files use: tar xvf 1581.tar. Note that if you just wanted to archive a few files and not a whole directory, you can replance the ~/class/c1581/* with the names of the files.

To compress files to save on disk space use compress or gzip. To use compress the command is: compress nameoffile.Z filestocompress. To use gzip the command is: gzip nameoffile.gz filestocompress. Once the files have been compressed, you may delete the files except for the compressed file you just created. To restore a .Z file use uncompress nameoffile.Z. To restore a .gz file use gunzip nameoffile.gz.

Note: Zip and unzip are also available. These programs are similar to the DOS pkzip and pkunzip. In fact, you can compress your files using zip, download them to your computer at home and use pkunzip to restore them. However, be careful, Unix file names can be longer than DOS file names. For example, if your compressed file contained the files big_ada_package_body.ada and big_ada_package_specs.ada, when you use pkunzip at home, you would get only one file called big_ada_.ada containing only the stuff of the later file.