Unix Lab Guide
Department of Computer Science (COS)
Guide to the UNIX Lab
The UNIX Lab in 103 Science houses a collection of computer systems running the UNIX/Linux and Windows operating systems. This collection includes the following stations:
|Machine Name||Machine Type||Architecture||Operating System|
This document will help to get you started using these machines. The following convention will be used throughout this document:
- Commands that you are to type at your shell prompt are typed in italics like the following: date
- Responses from the computer will be typed in bold print as follows: Wed Jan 10 15:00:31 EST 2008
- Any filenames are given in typewriter type style, like .profile
Please take the time to read the usage policies for the lab.
LOGGING IN TO THE UNIX MACHINES
The Login Screen (UNIX/Linux)
To log in to an Unix system, type your login ID (usually your last name), and then your password (initially your password is your student ID, without dashes, e.g., 050403) not your SSN. After you are logged on the system, Gnome should come up. Gnome has a toolbar going across the screen. To get to a shell prompt, right click on the desktop and select "New Terminal". If you would like to create another xterm window simply repeat the above procedure.
Logging in with SSH from another Unix System
If you are already logged into one of our linux/unix workstations you can simpy type ssh linux.cs.usm.maine.edu (Linux) or ssh sun.cs.usm.maine.edu (Solaris) from the Terminal. Upon first connection you will be promted to verify the key fingerprint, type yes. Then you will be prompted for your password. After a correct password is supplied you will have a shell.
Logging in from a Windows Machine (Machine not in the CS Lab)
Download a program called putty. From the PuTTY Download page. Get putty.exe, Save this file into the C:\Windows (Windows XP) or C:\Windows (Windows 9X/ME) directory whichever applies. At this point you can press the start menu, run and type putty -ssh email@example.com or putty -ssh firstname.lastname@example.org
Changing your Password
If you would like to change your password, you may do so by typing passwd. After you type this command, you will be asked for your current password. After typing the current one, you will be prompted to type the new password twice. Once this is complete, your new password will go into effect. There are a few restrictions on passwords that you should know. One of them is new passwords must be at least six characters long.
Logging out of the System
When you are finished using the system, please be sure that you log out. Sun machines: Actions -> Log Out. Linux: Redhat -> Log Out
LOGGING IN TO THE WINDOWS MACHINES
The Login Screen (XP)
You will be prompted for your username (usually your last name), password (initially your password is your student ID number, without the dashes, e.g., 059960) not your SSN. This user name and password is the same as your unix account.
Changing your Password
On the Windows machines you are NOT able to change your password. You need to login to any of the linux/sun workstations to change you password.
Connecting to the Unix Machines from XP
Go to Start->All Programs->Putty Connect and click on Putty. Enter linux.cs.usm.maine.edu 'Host Name (or IP addressO) the click the 'Open' button. This will start putty and if this the first time connection a window(Putty Security Alert) will popup asking if you want to trust the host you are connecting, click Yes. Enter your login credentials (username and password provided by the Computer Science Administrative Assistant for first time users otherwise send mail to o...@cs.usm.maine.edu).
Logging out of XP
When you are finished using the system, please be sure that you log out. To log out on the XP machines, click Start->Log Off
Working with Directories
When you log in on one of the machines, you will be placed in your home directory. The directory structure in UNIX is a hierarchical tree structure. The highest level of this structure is the / (root). To determine the current directory, type pwd. This command stands for print working directory. This is your home directory. You will always be placed here when you log in. To determine what files are in this directory, type ls or ls -al to get a long listing of all the files in the directory. The a option stands for all and the l option stands for long. Files that begin with a dot, such as .profile or .login, are considered hidden files. They are not shown in a normal ls listing.
The first field of a long directory listing tells you what kind of file this is, and the read, write, and execute permissions for that file. If the first character is a d, this is a directory. A hyphen as the first entry in this field signifies an ordinary file. You shouldn't have to worry about other types of files at this point. The rest of this field is read, write, and execute permissions for the owner, the group, and others, respectively. An r signifies read privileges for that person, a w write privileges, and an x execute privileges. The only other fields that you should be concerned with right now are the last five. These are the filesize, the date of the last modification to the file, and the name of the file, respectively.
To move to the root directory, type cd /. Do an ls -l listing to get an idea of the directory structure coming down from the root. There should be a bin, etc, usr, dev, and tmp on almost all UNIX systems. Let's try changing directories to bin, with the command cd bin. There are two ways to change directories. One method is using a relative path name. This will change your working directory relative to your current directory. The cd bin that you just typed is an example of this. The other form is using an absolute path name. An example of this would be cd /bin. Here you are changing your working directory relative to the root directory.
Creating directories is performed with the mkdir command. To return to your home directory, type cd with no arguments. Type pwd again just to make sure that you are back. Now create a test directory by typing mkdir test. Do an ls -l listing to be sure that this created the directory. Now cd test to put yourself into the test directory. If you do an ls -al, you will notice that there are two files in this directory. Every directory has the files . and .. when they are first created. The . is that directory and the .. is the parent directory. This means that if you would like to move up one directory, you can type cd .. to bring you back to your HOME directory. Now the test directory can be removed by typing rmdir test.
Working with Files
This section covers copying files, moving files, and deleting unwanted files. To copy files, use cp [source] [destination]. An example would be cp .profile .profile2. This would put a copy of .profile in .profile2, without changing .profile. If you wanted to have the .profile2 removed after copying it, you would use mv .profile2 .profile. This would copy .profile2 into .profile and remove .profile2 when finished -- mv is similar to command ren in DOS. If you just want to remove a file, that can be done with rm [filename], for example, rm a.out. This will remove the file a.out, if you have write permissions to that directory and file. If you are using the common desktop environment you can drag the files to where you want them by selecting them and dragging them to the destination folder. You can accomplish this by opening two windows with the application manager.
At some point in time, you will probably want to create or edit either text files or source code files. To do this you will need to use an editor. The two most popular editors for the UNIX system are emacs and vi. Vi is typically standard on all UNIX systems and emacs is installed on almost all systems. Both are installed on all of our systems.
To invoke emacs, just type emacs [filename], and the editor will load in that file, or create a new file if it does not already exist. To learn how to use emacs, just type emacs, and then when emacs loads up, press Ctrl-h then t. This will load up the interactive tutorial, which should fully explain to you how emacs works. Anytime that you wish to leave emacs, just type Ctrl-x Ctrl-c, which means press x while holding down the control key, and then press c while holding down the control key. This convention is used throughout the emacs manual, which can be found on the shelf in the lab.
Vi is invoked by typing vi [filename]. The screen will clear shortly and the vi working screen will show up. Vi works in two modes, command mode and text entry mode. You will start in command mode. You will need to type certain commands to enter text entry mode. If you type i, this will allow you to insert text starting before the current cursor position. To return to command mode, press the escape key Esc. Other useful commands are o (opens a new line below the cursor), O(opens a new line above the cursor), a (append after the cursor location), A (append at the end of the line), and dd (delete the current line). These should be enough to get you started. Once you are ready to leave vi, type :wq while in the command mode (You can also use Shift-ZZ). This will save your file and exit. If you do not wish to save the file, type :q! in command mode and you will exit vi without saving any changes that you have made. This is just a very tiny overview of vi. If you would like to learn more about it, we have a few books in the lab.
There are many ways that you can obtain help with any problems or questions that you may run into. There are manuals both online and offine. First this section will discuss the many online help facilities and then it will determine which offline manuals may be best suited to answer your questions.
The most frequently used online help is the man command. To use this to find information about, say the ls command, type man ls. If you would like to find more information about the man command itself, you may type man man. The Unix stations have many added online help features. One is the ability to typeman -k [keyword]. This will find all the commands relating to that keyword. An example would be man -k directory. The response will be a listing of the commands that refer to directories. This is useful if you want to do something, but do not know what command to use. You can then man the command to find out more information about it. Two more useful commands on the Unix stations are whatis and whereis. Typing whatis [command] will look up the command, and return the header from the man file, thus giving you a one line description of what the command does. Using whereis [program], will locate the source, binary and manual sections for the given program. For example, if you name your program "test", it won't run, but instead Unix will run the system command "test" by default. You could use the command whereis test to discover this name conflict.
OTHER USEFUL UNIX COMMANDS
Unix has a VERY large number of useful commands, so only a few of the important ones will be covered here. You can find out who else is logged into the system by typing who. This will give a listing of who is logged onto the machine that you are on and what time that they logged in. Another useful command is the pscommand. This will give you a listing of the processes running on your machine. If you would like to view the contents of a file, you could use cat [filename]. To have the file paginated so it doesn't fly right past you, use more [filename]. You will then have to hit space after each page, or q to quit. On our machines, there is an even better command than more, called less, and it allows you to move the text backwards as well as forwards. To move backwards, hit b.
You can communicate with users on other machines. You can communicate directly, using the talk command. To use this, type talk [user]. An example would betalk joe@teak. A message would appear on teak for joe, like Message from yourname@yoursystem at time ... The recipient of the message should now talk back the same way. Once the connection is established, everything typed by each user will appear in the other users window. To end the conversation, typeCTRL-C. To prevent annoyances from the talk command, you can type mesg n, which will prevent any users from writing to your terminal.
Using Electronic Mail
CS Mail is no longer supported. It is suggested that you use your University System Mail account to send mail which is of the format email@example.com.
How to Change your Prompt and Environment:
First you need to determine what shell you are by default, this is done by issueing the command echo $0. You should get the response -tcsh, -bash, -sh, -ksh or -csh, depending on how your account is set up. After you've determined what shell you are using you need to edit the file, which is in your home directory, accoding to the chart below,
The default scripts are commented and self-explainitory. If you do not have the default scripts or you have gotten into trouble you can issue /usr/local/bin/profileto reset the login scripts to the current system defaults.
If you run into any problems with your account, or mail, etc., explaining your problem and your problem will be solved by the administrator as soon as possible.
If you wish to print files on a printer, you can use the lpr command. There are two printers in the lab: an HP LaserJet4 laser printer and an HP DeskJet 870 Cxi color printer. These printers can print ascii test files or postscript files. Here are the commands you would use to print file test.c on these printers:
|lpr test.c||HP laser|
|lpr -Pcolorp test.c||HP color printer|
To print more than one file, you can list them all in one command, e.g., lpr test1.c test2.c test3.c. If you decide that you need to cancel a print job, type lprm -,or lprm job-number where job-number is determined using the command lpq -l. On each printer is a cancel button, it is an orange button labeled "Cancel". If you need to cancel a print job pres this button after or before your print job has started.
The Unix workstations provide a wide selection of programming languages. The most commonly used of these languages are C and C++. Also available are lisp, assembly language, awk, yacc and others. A complete description of how to use these are in the manuals.
Using the C Compiler
The C compiler is gcc. To compile a program, say hello.c, just type gcc hello.c. This will compile the source from hello.c and place the executable in a file called a.out. If you want to save the executable, move it by typing mv a.out hello. You can specify on the command line where you want the excutable to be put with the -o option. For example, gcc hello.c -o hello. Your executable will then be placed in the file hello. You will learn the other options as you begin to work with C more. The manuals also are very useful. There are reference pages for all of the C commands in section three of the manual. Reference pages in section two contain all the system calls.
Using the Lisp Compiler
To start it, type the command lisp from your shell prompt. This will bring you to the top-level loop. To exit, type press '(quit)' or '(exit)'.
Each machine has a symbolic debugger, just in case your program doesn't work. The debugger on the linux workstations is gdb. . For java development there is a text-based debugger, "jdb".
Secure FTP and WWW
If you wish to transfer files to and from your account, we recommend filezilla The server address for the Department of Computer Science' s SFTP site islinux.cs.usm.maine.edu. For instructions on using secure ftp click here
The Department of Computer Science's WWW server runs on one of the linux servers machines. If you want to publish your own web page on the internet, you can put the HTML documents and related files in a subdirectory called public_www under your home directory. If you name your main HTML document as index.html, then the URL address for that document would be http://www.cs.usm.maine.edu/~your-userid-here.
QUICK REFERENCE OF USEFUL COMMANDS
Here is a list of many helpful UNIX commands. This list is only provided to let you know what kind of commands exist. Please refer to a manual if you would like more information on a command, such as what arguments are needed for a command.
|COMMAND||WHAT IT DOES|
|awk||Pattern scanning and processing language|
|cd||Change working directory|
|chmod||Change file permissions|
|cp||Copy file data|
|date||Get date and time|
|diff||Compare two files|
|emacs||GNU Project Emacs (editor)|
|flex||Fast lexical analyzer generator|
|ftp||File transfer program|
|g++||GNU C++ compiler|
|gcc||GNU C compiler|
|grep||Search a file for a pattern|
|kill||Kill a process|
|less||GNU version of more|
|lex||Generate lexical analyzer|
|ln||Link to a file|
|lpr||Print files on laser printer|
|lpr -pcolorp||print files on color printer|
|make||Aid for generating programs|
|man||Display manual page online|
|mesg||Permit or deny messages|
|more||Display file data|
|mv||Move a file|
|od||Create file octal dump|
|passwd||Change your login password|
|ps||Print process status statistics|
|pwd||Print working directory|
|rm||Remove a file|
|sort||Sort file data|
|spell||Check text for spelling errors|
|tail||Print lines from a file|
|talk||Talk to another user|
|telnet||Used to communicate to another host|
|touch||Update times on a files|
|who||Print who is logged in and where|
|write||Write message to another user|