U WI Statistics UNIX Guide

This document is adapted from Stat 1000: Statistics Computer Handbook. Return to U WI Statistics Computing Facilities

UNIX for Beginners

You will be doing your statistics course work on a computers known as istat01, istat02, istat03, istat04, istat05 that are located on the first floor of the Computer Science and Statistics Building. istat computers are in room 1321, with a line printer is in the consultants room, 1359, and central processor in 2360. If you have any problems with the above hardware contact the  Stat Computer Committee.

On the other hand, if you have some general problem with the istat computers that is not hardware related you can ask your TA or your instructor. In particular, if you are registered for a statistics course but do not have an account, or if you've forgotten your password, or if you're having trouble invoking some other piece of statistical software, ask your TA.

The istat computers actually consists of a 1.6Ghz processor running the Red Hat UNIX operating system. It is available every day of the year, including holidays, except when there is a hardware failure, a full system backup, or preventive maintenance.

What You Need to Know about Hardware

For any terminal to function, it must:
  1. Be On (powered up). The computers in 1321 should remain On at all times. There is a Power-On indicator at the CPU that lights up when the terminal is On.  There is a separate Power-On indicator on the monitor.
If you have problems with a computer, you should check that the <Caps Lock> key is not depressed. Again, there is a Caps Lock light above the numeric keypad that should not be lit. Hit the <Caps Lock> key if it is.

If there appears to be a problem with line printers check with the person on duty. If no one is present, contact CSL.

What You Need to Know about Software

Enough on hardware: from now on, we will be considering software -- in particular, the UNIX operating system. The simplest view of an operating system is that it serves as a resource manager. That is, it
  1. makes it easier to manipulate resources (e.g., files)
  2. allows sharing resources (e.g., CPU time, the line printer)
The rest of this document summarizes how UNIX does this -- i.e., it explains some of the services UNIX provides (or tells you where to look to find out). Not much (if anything) will be said about sharing, except that it implies the need for protection (and thus, the login procedure and the file system structure).

Getting Started

Before UNIX will allow you to do anything, you are required to identify yourself. You are (publicly) known on the system by a login name. In addition, you have a private password which the system will ask you to provide to guarantee that you are who you claim.

The first time you use the system you should type the login newuser on the login: line and hit the return key. The cursor will go to the Password: line. Type newuser for the password for this account. Hit the return key.

- A single window will appear requesting the student to type in his/her 10 digit UW ID number. Move the mouse so the cursor is in that window, then type the ID number and answer the rest of the questions. These questions include establishing an initial password.

- Once the transaction is complete, that screen will stay up for about 30 seconds, then a logout screen will come up. Click OK.

- For future sessions, use the login name and password that have just been established. 

NOTE: whenever you type a password, any characters typed will not appear on the screen.

After a short time, a clock and a single terminal window will appear. The overall appearance of these windows is similar to the Microsoft Windows system on microcomputers. Resizing can be done with the left mouse button on the corners or sides of the windows. The title bar at the top of the window contains a menu button on the left, and minimize (iconify) and maximize buttons on the right.

Creating new windows is done from a menu accessed with the left mouse button when the mouse is on the screen background. (Inside a terminal screen, the left mouse button is used to delimit a selection for copying.)

After this, the system may type a message of the day -- some important message you should read.

Now UNIX should come back with your prompt, which will be something like % or istat01. You are now logged on.

To log out (end this session), close all programs, then click the logout button at to top right of the screen.

Exiting from the terminal window is not sufficient. Your files and privacy are compromised if you do not log out completely when you are done.


Typing Shell Commands

Any time UNIX (actually, a program running on UNIX, called the shell) prints your prompt, it is waiting for you to type a command. A command is a request that the system do something. The syntax (basic format) of all commands is
% command arguments
where % is the prompt provided by the computer, command is a single word, and arguments is zero or more words separated by spaces or tabs. You must press the <return> key after you type a command, or the system will not do anything.

UNIX has full read-ahead, which means that you can type as fast as you want, whenever you want, even when some command is typing at your. If you type during output, you input characters will appear inter-mixed with the output characters, but they will be stored away and interpreted in the correct order. So you can type several commands one after another without waiting for the first to finish or even begin.

If you make a mistake in typing a command, but see it before you've pressed <return>, there are three ways to recover.

  1. Your Erase character will erase the last character typed. Successive uses of this character will erase characters back to the beginning of the line (but not beyond).
  2. Your Erase character should be Control-H. To generate a control character, hold down the <Ctrl> key, then type the character. In this document, control characters are printed as, e.g., ^H. If your terminal has one, the <Backspace> key is equivalent ^H.
  3. Your Kill character will erase all of the characters typed so far on the current input line. Your Kill character should be ^U.
  4. Your Word Erase character (by default, ^W) will cause the last word you type to be discarded.
If you type a command that you do not want to run to completion, you can stop the program by typing ^C or <Break>. In addition, if you type a command that floods your screen with output (appearing faster than you can read it), you can Suspend printing by typing ^S . No output will be lost if you type this command: it just will not be sent to your terminal until you type your Resume character, ^Q .

If any of the above characters do not seem to be having the expected effect, typing the command

	% stty all
will tell you what your actual erase, kill, etc. characters are. Typing the command
	% reset
followed by a <Line Feed> rather than a <Return> should make the above characters work.

Some Useful Commands

Some other messages may also appear when you log on. If you get the message
	There are new messages
then there are some system messages that you have not yet read. You can read these by typing the command
	% msgs
You will be shown each message only once: if you wish to reread a message, the command
	% msgs -10
will allow you to look at (in order) the 10 latest messages. You may also get the message
	You have mail.
after you log on, UNIX provides a postal system so you can communicate with other users. There are various mail readers to read your mail.  See the documents at IMAP Mail Server.

Or

Type the command

	% mail
This will print a brief description of the messages waiting for you, with each message numbered. Type the number of a message you want to read (usually 1) or hit <Return>.

After a message has been displayed, mail waits for you to say, what to do with it (it prints the & prompt). The two basic responses are D, which deletes the message, and <Return>, which does not (so it will still be there the next time you read your mail). Pressing <Return> will also cause the next message to be displayed. After you have read all your messages, mail requires you to type q to leave the program. Any time mail expects input from you (i.e., when it has printed the & prompt, you can get a list of possible responses by typing ?.

Sending mail to some one else is easy. For example, if your TA has login teach, type

	% mail teach
followed by the text of your message on as many lines as you like. After the last line of the letter, type a <Period> followed by <Return>,
	.
And that's it. For practice, send mail to yourself (this isn't as strange as it might sound -- mail to oneself is a handy reminder mechanism). There are other ways to send/read mail -- for more details, read the manual section on mail. The UNIX Programmers Manual is kept on-line (so you can read it at your computer, rather than buying a copy). To get information about a command, e.g., mail, type
	% man mail
After a few moments, your screen will be filled with the first section of the manual entry on the command mail. (Occasionally, you may get the message
	Reformatting page . . . done
first -- just wait it out). At the bottom of the screen will be a line of the form
	--More--
Typing a <Space> causes the next screenful of the manual entry to be printed, typing <Return> causes the next line of the manual entry to be printed, and typing q gets you out.

Invoking man -k locates commands by keyword lookup. For instance to find the command to copy a file you could type

	% man -k copy
which would return a list of commands that contain the word copy in their descriptions. From this list you should be able to find the command that will do what you want. If need be you can then do a man on the commands listed to find the particular command you need. The command
	% help
on a line by itself will give you a one-page reminder of some of the more important UNIX commands.

File-oriented Commands

The main objects you use for your classes are files. A file is just a string of characters (sort of) saved (permanently) for you on disk. Some of the UNIX commands that help you manipulate files are:
	% ls
tells you what files you have.
	% more foo
prints the contents of the file foo on the screen. After each section (screenful) of the file is printed, a line of the form
	-- More --
appears. Typing a <Space> causes the next section of the file to be printed.
	% lpr foo
prints the contents of the file foo on the line printer. The file (usually) will not be printed immediately -- you will have to wait your turn. To see what files are waiting to be printed, you can use the command
	% lpq
If the queue is too long, or you otherwise decide that you really don't want something that you lpr'd, and your file is still in the queue, you can type
	% lprm <your login>
with <your login> replaced by your login name.

WARNING: you are only allowed to print a certain number of pages each term. To find out how much paper you have left, use the command

	% lpquot
The command
	% print foo
is similar to lpr foo. The only difference is that print breaks your output up neatly into pages and adds a header consisting of file name and page number at the top of each page.
	% mv foo bar
renames the (already existing) file foo as bar. That is, renaming on UNIX involves moving a file.
	% rm foo
removes the file foo. The command rm asks (cryptically) if you really want to do this: unless you type a Y, the file won't be removed. Be careful -- once you remove a file, it is gone forever.

There are three basic ways to created a file: by copying an existing file, by output redirection and by editing. The command

	% cp foo bar
creates a new file called bar that contains an exact copy of the file foo. If foo does not already exist, cp does nothing, and if bar already exists, cp asks if you really want to overwrite it.

With any command, you can have the output that usually comes to your terminal instead go into a file by

	% command > file
in which command is your command and file is the file name you want. That is, to get a hard-copy of the manual section on mail, do the following:
	% man mail > tmp
	% lpr tmp
	% rm tmp
The first of these commands redirected the output of the man command to the file tmp (instead of your screen). If the file tmp already existed, the shell would complain and refuse to allow you to overwrite it. Another way to achieve the same thing in one line is to use a pipe (the vertical bar |) as follows:
	% man mail | lpr
Text editors are also important system tools. The main full-screen text editors on our system are vi and emacs. Check at DoIT or ask your TA about documentation.

File System Structure

There is essentially no limit to the number of characters that may appear in a filename, and you are encourages to use descriptive filenames. All the same it is wise to keep filenames relatively short. Although you can use almost any character in a filename, common sense says you should stick to ones that are visible, and that you should probably avoid characters that might be used with other meanings. Also, names beginning with a period (.) are usually hidden form the ls command. To avoid pitfalls, you would do well to use only letters, numbers and the period until you are familiar with the situation.

You may wonder how, when you first make a file called foo, the system knows that there wasn't another foo somewhere else (especially since the person at the next terminal is reading this tutorial and is also calling her file foo). The answer is that the set of all files is orgainized into a big tree, with your files located several branches into the tree. The files that hold names of other files -- that have more branches of the tree below them -- are called directories.

Each user has a private directory, which contains only the files that belong to him or her. When you log in, you are in your home directory. Unless you take special action, when you create a new file, it is made in the directory that you are currently in; this is most often your home directory, and thus the file is unrelated to any other file of the same name that might exist in someone else's directory. The file system looks like

                         (/)
                        //|\\
                      / / | \ \
                    /  /  |  \   \
                  /   /   |   \     \
                p   bin dev tmp        u
               /|\  /|\ /|\ /|\       /|---------------
               /                        \              \
             stat                      stat            students
            //|\                       /|\\                 \
          / / |  \                    / | \  \               \
        /  /   \   \               /    |   \     \           \
      /   /     \    \           /      |     \       \        |
  Data  course  ftp  src     faculty  grad  special  staff     | 
                                       /|\                    /|\
                                     /  |  \                /  |  \
                                 suzi ralph anna          tom eve mary
There are two ways to name a file in the tree -- by specifying one of the following:
  1. The absolute path from where you are in the tree (called your current directory) to the file. To indicate a movement up the tree, .. is used. To indicate a movement down the tree, the name of the next directory or file is specified. Again, successive directories along the path are separated by // precedes the pathname). That is, if Eve were in her home directory eve above, her own file foo can be named as just foo, and mary's file foo'' could be named by ../mary/foo.
  2. The path relative to login. Mary's files could be accessed as ~mary/foo.
  3. The absolute path from the root of the tree to the file. In this case, the pathname will start with a /, and successive directories along the path are separated by /s; e.g., mary's file foo/u/stat/grad/mary/foo.
The first two approaches are preferred as they do not depend on the absolute position of directories. Sometimes these are reorganized to make for more efficient use of space. Or, you may want to take your files to another place. Use relative addresses whenever possible.

It is possible for you to walk around this tree, and to find any file in the system, by starting at the root of the tree and walking along the proper set of branches. Conversely, you can start where you are and walk toward the root. The basic tool is the command cd (change directory). which moves you around the tree.

If you give the command

	% cd /
you will now be in the directory at the root of the file system tree. If you now do an ls, you will see the names of the files at the lowest level of the tree. Any time you get lost in the tree, the command
	% pwd
will tell you where you are, and the command
	% cd
will take you back to your home directory. If you are in your home directory, you can create new directories below it. For example, the command
	% mkdir save
will create the new director save below your current directory, and you can then cd to this directory, and put files in it. You may find this particularly useful for saving backup copies of homeworks that you've turned in: if you've written your homework in your home directory, you can make a copy of it in save directory by the command
	% cp homework save/homework
UNIX keeps track of when files were created, so, if you don't touch anything once you put it in this directory, you will have proof positive that you finished the program (even after your TA loses the copy you handed in). Finally, you can remove an entire directory (and everything in it) by the command
	% rm -r scratch
where scratch is the name of the directory to be removed.

If your neighbor doesn't want you poking around in her files, or vice versa, privacy can be arranged. Each file and directory has a set of permissions associated which control access. To see what the permissions are for a file type ls -l. The output from this will be something like

	-rwxrw-r--1 login 18795 Aug 31 01:02 filename
where -rwxrw-r-- are the permissions. The mode printed under the -1 option contains 11 characters which are interpreted as follows: the first character is
	d		directory
	b		block-type special file
	c		character-type special file	
	l		symbolic link
	m		multiplexor-type character
	-		plain file
The next 9 characters are interpreted as three sets of three bits each. The first set refers to owner permissions; the next to permissions to others in the same user-group; and the last to all others. Within each set the three characters indicate permission respectively to read, to write, or to execute the file as a program. For a directory, execute permission is interpreted to mean permission to search the directory for a specified file. The permissions are indicated as follows:
	r		readable
	w		writable
	x		executable
	-		indicated permission is not granted
See the commands ls and chmod (and umask under csh) for details. As a matter of observed fact, most users find openness of more benefit than privacy in an academic environment.
Last modified: April 17 10:03:03 2000 by Colleen Brabender
(office@stat.wisc.edu)

(statwww@stat.wisc.edu)