
If you are using a workstation that is configured to run exclusively as an X display server, you may wish to acquire the Information Systems Document, UNIX 2, Introduction to X Windows.
Since this introduction to UNIX is brief, we encourage you to seek out more detailed introductory information. Information Technology offers free Short Courses on UNIX that you can sign up for. The Computing Resource Area, located in B40 in the basement of Fondren Library, has a number of very good introductory books on UNIX available for checkout. These books go into more detail and cover more of the operating system than will be covered in this document. You can also purchase some introductory UNIX books at the Rice Campus Store or almost any local bookstore with a computing section.
This document introduces you to the basics of UNIX, including:
Information Technology maintains groups of machines for different groups of users; these groups of machines are known as domains. The major Information Technology domains are Owlnet, the Rice UNIX Facility (RUF), and Information Technology administration. Other departments or divisions may have their own domains, such as Computer Science or Electrical and Computer Engineering. Accounts in one domain are not valid on machines of other domains. IT workstations are labeled with its name and domain. If you have an Owlnet account, use the workstations or terminals in A121 or B223 Abercrombie, 241 Mechanical Engineering, 102 Ryon Lab, 105 Mudd, 221 Physics, Fondren Library, the Student Center, or the workstations at your residential college.


If the screen is entirely black, then a screen-saving program is running automatically to protect the monitor from damage. Moving the mouse or pressing the RETURN key should "wake up" the display. (If you see the words "This screen has been locked..." then someone else is using the workstation, but they are temporarily away from their seat. Look for an unoccupied machine.) Move the mouse until the cursor (a black `X') is on top of the white box.
After you have entered your userid, the system will prompt you for your password (by displaying the word "Password:" if it is not already on the screen, or by moving the cursor behind the word "Password:" already on your screen). Enter your password and press the RETURN key. Notice that the system does not show or "echo" your password as you type it. This prevents other people from learning your password by looking at your screen.
If you receive a message similar to "Login failed, please try again," you may have typed your userid or password incorrectly. Try again, making sure to type in your userid and password correctly. If you are still having problems, go to the Consulting Center (713-527-4983, 103 Mudd Labs) and ask for help.
When you have successfully logged on, the system will pause for a moment, and then display a few lines telling you when and from which machine you last logged on, and any messages from the system administrator.
On X terminals, you will get a window containing system information. After reading it, use the left mouse button and click on either the "Help" or "Go Away" button, depending on what you want. Help puts you into a help system; Go Away allows you to begin your work.
Your new account is provided with a set of command procedures which are executed each time you log in. You can change part of your UNIX environment by changing these setup files (accounts on Information Technology supported systems are set up to produce a default environment). For further information, check the Sun manual SunOS User's Guide: Customizing Your Environment, available for building use only in the Operations Center, 109 Mudd Lab.
The system will then display the command prompt. The prompt signals that the system is ready for you to enter your next command. The name of the workstation followed by a percent sign (%) forms the command prompt (e.g. chub.owlnet.rice.edu%). Once you finish typing a command, you must always press RETURN to execute it.
You should never turn a workstation off. Turning off a terminal does not necessarily log you out. If you are having trouble logging out, see the section, Troubleshooting.
For example, changing your password from Kat899 (based ona dictionary word) to B00z00e (a bad password) will look similar to the following example, except that the keystrokes for you old and new password will not be echoed on the screen.
These passwords are bad examples and will not work. Try using this technique:
All she wants to do is dance => Aswtdid
Remember, choose your OWN passwords.
On many systems, the password change does not take effect immediately, even though you have finished with the passwd command. It can take upwards of an hour for the system to install the new password, due to the scheduling of the password changing process. Thus you should be prepared to use your old password to login again shortly after changing it.
If you should ever forget your password, you can go to the Information Desk in 103 Mudd Lab and request that a new password be generated for you. You will need to bring your Rice ID card with you to pick up your new password.
In addition to processing your command requests, UNIX shells have their own syntax and control constructs. You can use these shell commands to make your processing more efficient, or to automate repetitive tasks. You can even store a sequence of shell commands in a file, called a shell script, and run it just like an ordinary program. Writing shell scripts is a topic discussed in the class notes for the UNIX III-Scripts Short Course.
A UNIX command line consists of the name of the UNIX command followed by its arguments (options, filenames and/or other expressions) and ends with a RETURN. In function, UNIX commands are similar to verbs in English. The option flags act like adverbs by modifying the action of the command, and filenames and expressions act like objects of the verb. The general syntax for a UNIX command is:
The brackets around the flags and options are a shorthand way to indicate that they are often optional, and only need to be invoked when you want to use that option. Also, flags need not always be specified separately, each with their own preceding dash. Many times, the flags can be listed one after the other after a single dash. Some examples later on will illustrate this concept.
You should follow several rules with UNIX commands:
directs the system to put the output from the date command, which merely reports the time and date as the system knows it, into the file named file rather than printing it to your screen. One thing to keep in mind about ">" is that each successive redirection to a particular file will overwrite all of the previously existing data in that file. To append to the end of a file, use ">>" instead, like so:
Another redirection is "<", which tells the command to take its input from a file rather than from the keyboard. For example, if you have a program that requires data input from the keyboard, you may find that you have to type the same data a large number of times in the debugging stage of program development. If you put that data in a file and direct the command to read it from there you will only have to type the data once, when you make the data file.
If you do this, you would see the same response from program as if you had typed the data in from the keyboard when requested.
You can also combine both kinds of redirection as in,
The data in the file datafile will then be used as input for program and all output will be stored in outputfile.
If you want to accumulate output from different sources in a single file, the symbol ">>" directs output to be appended to the end of a file rather than replacing the previous (if any) contents, which the single ">" redirection will do.
A final I/O redirection is the pipe symbol, "|." The "|" tells the computer to take the output created by the command to the left of it and use that as the input for the command on the right. For example, we could type:
This would use the output of the date command as input to another program.
NOTE: Many, but not all, interactive programs accept input from a file.
The man pages provide an in-depth description of command-name, with an explanation of its options, examples, and further references. The information is an electronic duplicate of the paper reference manual pages. Use the man command for explicit information about how to use a particular command. Use the -k option to search for a keyword among the one line descriptions in the help files.
The command apropos serves exactly the same function as man -k and is used in the same way.
You can read about the man command itself using man. Type man man at the prompt. The UNIX reference manual is divided into eight numbered sections:
You can see the command summary for each section by typing:
where # is one of the eight section numbers.
In addition, other applications that reside on your system may have man pages. These pages can often be called up in the same manner as the operating system man pages.
TABLE 1. Special Keys and Control Characters
When you place a single period in the middle of a filename, the part after the period is commonly referred to as an extension or suffix and usually indicates what type of information is stored in the file. You may use any extension desired; a text file might have the extension .txt or .text; a note may have the extension .note, and so forth. UNIX does not require extensions, but they can be used to help identify similar types of files. Since some UNIX programs (especially compilers) look for certain standard extensions, it is common practice to use the following conventions: .h for header files, .c for C source files, .f for FORTRAN, .p for Pascal, and .s for assembler source files. So the file wright.txt indicates a text file whereas the file payroll.c indicates a C program called payroll. For more information on programming conventions, see the section, Additional Resources.
Some UNIX files begin with a period, for example, .cshrc or .login. Files that begin with a period will not appear in a normal directory listing and are usually UNIX environment and application setup files.
A large grouping of files and directories is referred to as a file system. File systems are related to the disk size and structure, and to the internal structure of UNIX. What you should remember is that users' files and directories are usually on a different file system than the system's files and directories. If the number of users is large, as on Owlnet, the user files and directories may be on more than one file system.
You can create a file without a text editor by using the cat command (short for concatenate) and the ">" (redirect output) symbol. To create a file using the cat command, type:
where new-filename is the name you wish to give the file. The command cat generally reads in a file and displays it to standard output. When there is no filename directly following the command, cat treats standard input as a file. The ">" symbol will redirect the output from cat into the new filename you specify. cat will keep reading and writing each line you type until it encounters an end-of-file character. By typing CTRL-D on a line by itself, you generate an end-of-file character. It will stop when it sees this character. Try it, using this example as a guide:
When you reach the end of each line, press the RETURN key. You can only correct mistakes on the line you are currently typing. Use the DELETE key to move the cursor back to the mistake and then retype the rest of the line correctly. When you have completed the last line, press RETURN and type CTRL-D.
Sometimes the files you want to view are very long. When using the cat command, the text will scroll by very quickly. You can control the flow of text by using CTRL-S and CTRL-Q. CTRL-S stops the flow of text and CTRL-Q restarts it. If you use CTRL-S, stopping the flow of text, and so on, you must remember to type CTRL-Q or the computer will not display any output, including anything that you type.
more is a program that displays only one screen of information at a time; it waits for you to tell it to continue. Type more followed by a filename.
The computer will display one screen of text and then wait for you to press the space bar before it displays the next page of text, until you reach the end of the file. Pressing the "?" character will show help for more. A utility of greater power called less is available on many systems; it allows reverse scrolling of files and other enhancements. It is invoked the same way as more.
Below is a list of options you can tack on to ls:
If you have many files, your directory list might be longer than one screen. You can use the programs more or most with the "|" (vertical bar or pipe) symbol to pipe the directory list generated as output by the ls command into the more program. more or less will display the output from ls one page at a time.
where filename is the file you wish to copy and newfilename is the file you are creating.
The example created a new file called sample that has the same contents as practice. If sample already exists, the cp command will overwrite the previous contents. New accounts are often set up so that cp will prompt for confirmation before it overwrites an existing file. If your account is not set up in this manner, use the -i option (cp -i) to get the confirmation prompt, like so:
This moves the contents of sample into the new file workfile. (Note: Moving a file into an existing file overwrites the data in the existing file.) New accounts are often set up so that mv will prompt for confirmation before doing this. If your account is not set up in this manner, use the -i option (mv -i) to get the confirmation prompt.
Important: rm can be very dangerous. Once a file has been removed you cannot get it back, except, possibly, from system backups (which may or may not contain the file). It may take the system administrators several days to to recover your deleted file, so use a great deal of caution when deleting files. New accounts are often set up so that rm will prompt for confirmation. If your account is not set up in this manner, use the -i option to get the confirmation prompt.
Links are useful for cross-referencing files. If you know that you will need to access a file from different directories, creating links is a better alternative to making a copy of the file for each directory (and then having to alter each one every time a change is made to the original). It is also more convenient than having to use the file's full pathname every time you need to access it. Another use for linking a file is to allow another user access to that particular file without also allowing entry into the directory that actually contains the file. The kind of link you will want to create is called a symbolic link. A symbolic link contains the pathname of the file you wish to create a link to. Symbolic links can tie into any file in the file structure; they are not limited to files within a file system. Symbolic links may also refer to directories as well as individual files. To create a symbolic link to a file within the same directory, type:
where originalFile is the file that you want to link to and linkName is the link to that file. To create a link in a directory other than that of the original file, type:
If you create a link within the same directory as the original file, you cannot give it the same name as the original file. There is no restriction on a file's additional names outside of its own directory. Links do not change anything about a file, no matter what the link is named. If someone makes a link to one of your files, and you then delete that file, that link will no longer point to anything and may cause problems for the other user.
NOTE: You should always use symbolic links when linking to files owned by others.
To get a list of the printers available to your machine, type:
lprloc lists all of the printers that your system knows about, by name, along with their type and location. To get some status information on the printers, use the command lpstat -p.
NOTE: Line printers are used for text-only files. Laser printers are needed to handle graphics or PostScript files. PostScript is a page-description language developed by Adobe Systems, Inc. and was specially designed for creating graphics and typography on a printed page. The option flag -P printername specifies which laser printer to use and is optional (as indicated by the brackets). When no printer is given, the print command uses the system default printer. However, on some systems such as Owlnet, you must always specify a laser printer with the -P flag. For more information on printing commands, use the man command to consult the manual pages on lpq, lpr, and lprm. Printing accounting information is available by running this command: pacinfo.
All files and directories in the UNIX system are stored in a hierarchical tree structure. Envision it as an upside-down tree, as in the figure below.

At the top of the tree is the root directory. Its directory name is simply / (a slash character). Below the root directory is a set of major subdirectories that usually include bin, dev, etc, lib, pub, tmp, and usr. For example, the /bin directory is a subdirectory, or "child," of / (the root directory). The root directory, in this case, is also the parent directory of the bin directory. Each path leading down, away from the root, ends in a file or directory. Other paths can branch out from directories, but not from files.
Many directories on a UNIX system have traditional names and traditional contents. For example, directories named bin contain binary files, which are the executable command and application files. A lib directory contains library files, which are often collections of routines that can be included in programs by a compiler. dev contains device files, which are the software components of terminals, printers, disks, etc. tmp directories are for temporary storage, such as when a program creates a file for something and then deletes it when it is done. The etc directory is used for miscellaneous administrative files and commands. pub is for public files that anyone can use, and usr has traditionally been reserved for user directories, but on large systems it usually contains other bin, tmp, and lib directories.
Your home directory is the directory that you start out from when you first login. It is the top level directory of your account. Your home directory name is almost always the same as your userid.
Every directory and file on the system has a path by which it is accessed, starting from the root directory. The path to the directory is called its pathname. You can refer to any point in the directory hierarchy in two different ways: using its full (or absolute) pathname or its relative pathname. The full pathname traces the absolute position of a file or directory back to the root directory, using slashes (/) to connect every point in the path. For example, in the figure above, the full pathname of file2 would be /usr/bin/file2. Relative pathnames begin with the current directory (also called the working directory, the one you are in). If /usr were your current directory, then the relative pathname for file2 would be bin/file2.
If you are using C shell, TC shell, or the Bourne-Again shell, UNIX provides some abbreviations for a few special directories. The character "~" (tilde) refers to your home directory. The home directory of any user (including you, if you want) can be abbreviated from /parent-directories/userid to ~userid. Likewise, you can abbreviate /parent-directories/youruserid/file to ~/file. The current directory has the abbreviation . (period). The parent of the current directory uses .. (two consecutive periods) as its abbreviation.
By typing the ls -a command, you can see every file and directory in the current directory, regardless of whether it is your home directory. To display the contents of your home directory when it is not your current directory, enter the ls command followed by the full pathname of your home directory.
If you are using a shell other than the Bourne shell, instead of typing the full pathname for your directory, you can also use the tilde symbol with the ls command to display the contents of your home directory.
To help you distinguish between files and directories in a listing, the
ls command has a
-F option, which appends a distinguishing mark to the entry name
showing the kind of data it contains: no mark for regular files; "/"
for directories; "@" for links; "*" for executable
programs.
Using pwd will show you your new current directory.
To get back to the parent directory of projects, you can use the special ".." directory abbreviation.
If you get lost, issuing the cd command without any arguments will place you in your home directory. It is equivalent to cd ~, but also works in the Bourne shell.
For example,
moves the file sample.txt into the projects directory. Since the mv command is capable of overwriting files, it would be prudent to use the -i option (confirmation prompt). You can also move a file into a another directory and rename it at the same time by merely specifying the new name after the directory path, as follows:
As with mv, the new file will have the same name as the old one unless you change it while copying it.
The new directory name must not exist before you use the command. The new directory need not be in the current directory. You can move a directory anywhere within a file system.
UNIX was designed and implemented by computer scientists working on operating system research. Many of the fundamentals of UNIX reflect this origin in academia. A low concern for security is one of the hallmarks of UNIX operating systems. Therefore, unless you act to restrict access to your files, chances are high that other users can read them.
Every file or directory in a UNIX file system has three types of permissions (or protections) that define whether certain actions can be carried out. The permissions are:
write ( w )
execute ( x )
Group ( g ) Several users purposely lumped together so that they can share access to each other's files.
Others ( o ) The remainder of the authorized users of the system.
Each file or subdirectory entry in a directory listing obtained with the -l option consists of seven fields: permission mode, link count, owner name, group name, file size in bytes, time of last modification, and the filename (the group name appears only if the "g" flag is also specified, as in ls -lg).
The first 10 characters make up the mode field. If the first character is a "d" then the item listed is a directory; if it is a "-" then the item is a file; if it is an "l" then it is a link to another file. Characters 2 through 4 refer to the owner's permissions, characters 5 through 7 to the group's permissions (groups are defined by the system administrator), and the last three to the general public's permissions. (You can type id to verify your userid and group membership.) If a particular permission is set, the appropriate letter appears in the corresponding position; otherwise, a dash indicates that the permission is not given.
The second field in the output from ls -l is the number of links to the file. In most cases it is one, but other users may make links to your files, thus increasing the link count. A special warning to people using links to other people's files: your "copies" of their files can be counted against them by the file quota system available on certain UNIX variants. This is why making links other than symbolic links to other people's files is strongly discouraged. The third field gives the userid of the owner of the file. The group name follows in the fourth field (if the -g option is used in conjunction with -l). The next two fields give the size of the file (in bytes) and the date and time at which the file was last modified. The last field gives the name of the file.
A file's owner can change any or all of the permissions with the chmod (change mode) command. The chmod command allows you to dictate the type of access permission that you want each file to have. In the previous example the current permissions for myfile are read for everybody, write for the owner, and execute by no one.
The arguments supplied to chmod are a symbolic specification of the changes required, followed by one or more filenames. The specification consists of whose permissions are to be changed: u for user (owner), g for group, o for others, or some combination thereof (a (all) has the same effect as ugo), how they are to be changed (+ adds a permission, - removes a permission, and = sets the specified permissions, removing the other ones) and which permission to add or remove (r for read, w for write, and x for execute). For example, to remove all the permissions from myfile:
To allow read and write permissions for all users:
chmod will also accept a permission setting expressed as a 3-digit octal number. To determine this octal number, you first write a 1 if the permission is to be set and a 0 otherwise. This produces a binary number which can be converted into octal by grouping the digits in threes and replacing each group by the corresponding octal digit according to the table below.
TABLE 2. Symbolic to Octal Conversions
This shows that the octal equivalent of rw-r--r-- is 644. The following example illustrates that the permissions for myfile have been reset to the values with which we began.
When you create a file the system gives it a default set of permissions. These are controlled by the system administrator and wil vary from installation to installation. If you would like to change the default which is in effect for you, choose your own with the unmask command. Note that the pemission specified by the unmask setting will be applied to the file, unlike that specified in the chmod command, which normally adds or deletes (few people use the = operator to chmod).
First issue the command without arguments to cause the current settings to be echoed as an octal number:
Suppose you decide that the default settings you prefer is rwr----. This corresponds to the masking bit pattern 000010111, so the required mask is 026:
Now, if you create a new file during this session, the permissions assigned to the file will be the ones allowed by the mask value.
would erase all files in your current directory (although by default, you would be prompted to okay each deletion). The wildcard * should be used carefully.
ps displays the process ID, under PID; the control terminal (if any), under TT; the state of the process, under STAT; the cpu time used by the process so far (including both user and system time), under TIME; and finally, an indication of the COMMAND that is running.PID TT STAT TIME COMMAND 4804 p3 S 0:00 -sh (csh) 1352 p3 R 0:00 ps 3874 p7 IW 0:25 xclock -g 90x90-0+0 3875 p7 S 0:48 xbiff -g 90x90-95+0 3879 p7 S 0:10 twm 3880 p7 IW 0:00 -bin/csh (csh) 3892 p9 IW 0:24 /usr/local/bin/elm
The state of the process is indicated by a sequence of letters. The man pages for ps explain what the letters mean if you want to know. For most purposes, you won't really need to know what the letters mean.
Adding an & (ampersand) at the end of the command line instructs UNIX to run the job in the background.
The response you receive will be something like this:
[1] 5432This particular response means that you have one job running in the background (and its job number is 1), and its process identification number (PID) is 5432. You will need to know the PID if you want to abort the job. This is known as killing a job. To kill the job in the above example, you would type:
or, if there' only one job running called "jobname,"
In the C shell, the job number can be used to control which jobs run in background or foreground. The job number is used when switching a job that is processing in the foreground to the background, and one that is processing in the background to the foreground. To do the former, first press CTRL-Z to suspend the job. Then type:
To switch the job to the foreground, simply type:
If you have forgotten the job number, type the command jobs to see a list of the jobs that are running in the background at the moment.
Note: The rules imposed by system administrators about where and how to run background jobs varies from network to network and changes over time. It is important to stay current with the background job policy of your network.
The available priority numbers for users ranges from 1 to 19 with 19 being the lowest priority. In other words, the higher the nice value, the lower the processing priority. (Note: It is important to check the network policy for the required nice value for background jobs on your system; they are usually required to be niced and your job may be downgraded in priority if it was niced at the wrong value.) Set your command at the required nice value or higher. If you do not include a number argument, the value will default to 4 for the C shell and 10 for the Bourne shell.
For example, if you wanted to run a long non-interactive job, and you didn't have to have the results of this job right away, you should run it in the background and set a high nice value. Using the C shell, you would type:
You may then have to supply your password. You should also get the messages about logging in that are used on newSystem. If your userid is different on newSystem you will have to use the form:
Problem: The computer types everything in upper-case with slashes in
it.
Problem: The system replies "There are stopped jobs" when you
try to log out.
Type jobs to see what they are, then type kill %% to terminate all
stopped background jobs. After that, try logging out again.
Problem: The system replies, "Not in login shell."
First, type exit, press RETURN, and then type logout at the prompt, if
necessary.
Problem: Nothing seems to work and you can't log out.
You might be stuck in a program or shell other than the login shell. Press
RETURN to clear any previous commands; then try typing CTRL-C, q, :q, :q!, exit,
CTRL-D, CTRL-Q, or CTRL-Z to get back into the login shell. Then try logout again.
The following sequence might also work if your terminal is NOT connected directly
to your real host machine. Press RETURN, then type "~." followed by
RETURN.
If you need additional help, go to the Consulting Center in 103 Mudd Lab during consulting hours or call 713-527-4983. You can also send electronic mail to the Consulting Center by using the address: problem@rice.edu, or better yet, visit the website http://problem.rice.edu.
Information Systems has a number of tutorial and reference documents available free of charge in the Consulting Center in 103 Mudd Lab. Below are some of the UNIX-related documents.
The Computing Resource Collection (CRC) in B40 Fondren Library (basement) has a full set of UNIX reference documentation as well as a large checkout collection of books and manuals on UNIX and other related topics, including some very good introductory books.
The Consulting Center in 103 Mudd Lab has consultants available to troubleshoot problems and to provide general assistance. A schedule of hours is posted outside the door of Room 103. You may also send electronic mail to the userid problem@rice.edu with questions about UNIX, or use the WWW Problem Interface with Netscape, located at the URL http://problem.rice.edu/
The Rice Campus Store has introductory and advanced books on UNIX, as does any bookstore with a computer books section. Your professor may also have some course notes available at the Rice Campus Store.
If you would prefer a hands-on tutorial introduction to UNIX, Information Systems offers free non-credit, one to three hour sessions on various computing topics, including an introduction to UNIX. Short Course calendars are available outside 103 Mudd Lab. For more information, call 713-527-4983.