UNIX Tutorial

This tutorial is designed to introduce you to the rudimentary features of the UNIX operating system and its various tools. We will be talking about the following topics:


Logging In

Hopefully everyone has logged in once, and knows their password. If you want to change your password, you can use the passwd command.

Login to the system. You will need to open a terminal window by clicking on the icon of a computer screen.

Play around with the windows. You can move and resize the windows. The top-left button on the titlebar of a window allows you to move a window to another workspace, to close the window, etc. You can minimize the window and it will turn into an icon. Try this, then double-click on the icon to reopen the window.


Files and Directories

Type ls. This will give you a list of the files in your current directory. You should be in your home directory, because you are automatically placed there when you log in. The name of your home directory is /u/username, where username is your login name.

The following commands manipulate files and directories:

ls
rm
mkdir
rmdir
cd
chmod
cp
mv
Lists the files and directories in a directory
Deletes a file.
Creates a new directory
Deletes an empty directory.
Changes the current directory
Changes permissions on a file or directory
Copies a file
Moves/renames a file or directory

The first six commands take one or more arguments, indicating the name(s) of file(s) on which you want to perform the operation. (Additionally, ls and cd can be used with no arguments; with no arguments, ls lists the contents of the current working directory, and cd changes your current working directory to your home directory.) The last two commands are usually used with two arguments, in the order source destination.



To familiarize yourself witht these commands, we'll work through some examples:

mkdir temp Create a new directory
cd temp Move to the new directory
cp /u/sacm/tutorial/* . Copy all the files in the directory /u/sacm/tutorial into this directory
ls See what we copied
cat bible Dump the contents of the file bible to the screen
more bible Same as cat, but one page at a time. Type space to advance a page, "q" to quit.
chef < bible Run the program "chef" giving the contents of "bible" as input
chef < bible > chefbible Again, but save the output of "chef" in the file "chefbible"
ls See the new directory listing: note the new file
more chefbible View the contents of the new file



The following three commands are equivalent:

grep Bork chefbible View all the lines in the file "chefbible" that contain the word "Bork"
chef < bible | grep Bork Run the program "chef" with input taken from "bible" and ouput sent to the program "grep". grep will echo all lines containing the word "Bork".
cat bible | chef | grep Bork Note that "chef < bible" is equivalent to "cat bible | chef".



The input and output of program can be directed with <, > and | :

program < file Run program, with input taken from file
program > file Run program, with output sent to file
program1 |  program2 Run program1, with output sent to program2

If the source of input of a program is not specified by "<", then it is taken from the keyboard. If the destination of output of a program is not specified by ">" or "|", then it is sent to the screen.


Permissions

If you type "ls -l" instead of simply "ls", then you will get the long directory view. The leftmost column shows the permissions of each file. Permissions are important if you want to share files. For example:

drwx------  2 joe  student    512 Sep 16 15:34 adirectory
-rw-r--r--  1 joe  student  40462 Sep 16 15:30 bible
-rwx------  1 joe  student  16384 Sep 16 15:30 chef
-rw-------  1 joe  student  41038 Sep 16 15:31 chefbible

The first letter identifies directories with "d" and files with "-". The next nine letters indicate the permissions on the file/directory. These are in three groups of three letters. The first three are owner permissions, the second group permissions, and the third world permissions. An "r" means the file is readable, a "w" means it is writeable, and an "x" means it is executable.

The third column lists the login name of the owner of the file, and the fourth column lists the name of the group the file is in. All undergraduates are in the group "student" and all files they create are automatically in the group "student".

The chmod command changes file permissions. If you want to know how to use this command, type "man chmod" to read the manual for the chmod command. The man command will give you the manual for virtually any UNIX command.


Editing Files

The editor that we recommend is called emacs. Type "emacs &" in your terminal window to get a new emacs window. Emacs does many many things, but we list only those few commands that are essential for editing text files:

C-x C-s
C-x C-w
C-x C-f
C-x C-c
C-k
C-y
Save
Save as
Open file
Exit
Cute
Paste

C-x means "hold down the control key and type x". A quick tutorial:

Open the file "chefbible" by typing "C-x C-f chefbible <enter>". General editing is intuitive, but cut and paste is a bit confusing. The cut command cuts text from the cusor to the end of the line and saves it for you to paste later. Move the cursor down to the second verse, at the beginning of the line starting "001:002". Tpye "C-k" until the third verse appears underneath the cursor. Verse two is now in the kill buffer. You can now paste copies of verse two at will. Type "C-y" once to restore verse two to its original position. Now move the cursor somewhere else and type "C-y" again. The same text is pasted again.

If you want to save these changes, type "C-x C-s" or "C-x C-w". When you are done with emacs, "C-x C-c" will quit the program and destroy the window.


Mail

There are many UNIX e-mail programs, but most people use one of the following three:

mail
This is a bare-bones mail program which is somewhat confusing and not very powerful. if you read mail with this program, you will notice the presence of a file "mbox" in your home directory. this is where mail you have read is stored after you quit the program.

elm
This is a more intuitive tool than mail, but still a bot difficult to use. elm will create a directory called "Mail" in your home directory.

pine
This is the simplest mail program to use and is our recommendation. It is menu-driven and asks you questions. pine will create a directory called "mail" in your home directory.


Remote Access

You can read mail and do all of your programming tasks from your dorm room (through Dormnet) or from and of the Macintosh or PC computer clusters on campus. To do so, start up the "telnet" program on the computer you're using, and tell it you want to connect to arizona.princeton.edu. This will automatically connect you to one of the CIT Sun servers called phoenix, tucson, flagstaff and yuma.

Your files (such as your mailbox and home directory) do not actually reside on any of the CIT Sun servers or on any of the CS 101 workstations. Instead, they reside on a server at CIT which is accessed whenever you log on to any CIT UNIX machine. Therefore, you can use your files and read your mail from anywhere on campus, as long as you are connected to a UNIX machine administered by CIT.

It is also possible to use your files from a non-Sun UNIX workstation on campus, such as the Silicon Graghics machines in the E-Quad. If you use one of these machines, however, we suggest you use it to log in to a CIT Sun server, since the UNIX variants run on these non-Sun UNIX machiones are somewhat different from Sun's UNIX. Also, most Computer Science classes require that you turn in programs which have been compiled on a Sun. programs compiled on one brand of UNIX machine are not compatible with those compiled on another brand.


Getting Help

If you have general UNIX questions, send mail to cithelp@phoenix or go to the CIT Help Desk at 87 Prospect Street. To report a technical problem with a CIT Sun machine, send mail to sunadmin@phoenix.