comp101 Introduction to Computer Science I

Spring 2008

Lab #1


In this first lab you will be introduced to the computing environment using the new experimental revision of the eagle compute server. eagle is the name of our "log in from anywhere and do significant work" style compute server on the Bridgewater campus. This year we are moving from a Sun Solaris based server to a Red Hat Linux based server. I'm very familiar with both systems so I've volunteered my classes to spearhead the transition. Our server will be called csdev01

but why unix?!

Many of you are very familiar with MS windows and some of you with Apples Mac OS/X operating systems. Those are fine operating systems used in many situations. However, computer scientists should be familiar and at least somewhat comfortable with a broad range of systems and environments. Computer scientists should have experience with as many systems as possible before they graduate.

If you are familiar with Unix you may know how to do some or all of the following tasks. Do them all the same. If you are new to Unix, these exercises will get you up and running with most of the tools you need to successfully complete the lab assignments of this course. Some further tools will be introduced as we need them in later labs.

You should plan to work on the lab outside of class time, though I will walk you through the first first couple of steps. 

Read through the entire lab before you start working on your own, so that you know what to expect. Make sure you save your work often, and keep track of what you are expected to submit.


The objective of this lab is to introduce you to the Unix operating system and some of the tools available to you so that you can work on the labs independently. In support of this objective, you will learn not only the basics of many tools, but also how to obtain further information by consulting on-line documentation.

Preparatory work

Make sure that you can login to the BSC network using your usual username and password.

Purchase your course textbooks

    If you have not already done so, make sure you have bought all of your course textbooks. .

Lab Tasks

Your instructor has briefly gone through the tasks listed below during lecture to help prepare you for this lab. We will do the first task or two in class. You must then carry out each of the following tasks on your own in the lab or logging in from your computer at home. 

Logging in - Connecting to the system

Your first lab task is to log in to your eagle computer account. Your eagle account is for the computer science server only. This account is separate from your regular BSC account. (If you change the password for one - the other password will remain the same.)


Your instructor will give you your csdev01 account user name. These usernames are autogenerated based on the class you are taking.


We will start xWindows from the beginng. On the lab machine, select <start><departments><computer science><cygwin><start x windows> and wait a few moments while it starts the graphical shell (you'll see a small X appear in your windows system tray.) then a command terminal will pop up for you to begin with.

Now use ssh to log in. ssh is the “secure shell”.

Ssh is available built in on Macs and Linux/Unix computers. For windows users there is a free program called putty that you can download and install to give you ssh capability. (see for the putty home page.)

Your instructor will walk you through logging in for the first time during class.


now log into csdev01.

ssh -X -Y <usename> (where you must replace <username> with your actual eagle username)

Note the -X (that's a capital X) this tells the computer that you want to use "x forwarding" (put the graphical windows on the machine in front of you thank-you very much)

The -Y is an option to get around a security oddity with running windows remotely. 

Note: Unix does not echo a '*' character as you enter your password. The server sees what you type, but doesn't give any feedback to the user - its appears to be doing nothing.

 Also note that unix passwords are case sensitive as most are these days.

Unix Background

Unix is the name of the operating system that is running on csdev01. An operating system (or OS) provides basic services to both programs (applications) running on the machine and to users who are working on the machine. Examples of services provided by an OS are a facility to read the contents of a file from a disk, or run multiple programs at one time (multi-task).

X-windows is window system, or graphical user interface (GUI) to the underlying Unix operating system. X-windows is thus separate from the operating system. A window system manages windows on a screen and provides a graphical way of interacting with the operating system.

On personal computers it is becoming more and more difficult to distinguish between the operating system and the window system as they are becoming more tightly integrated. In the Unix world, however, the separation is still clear, and it is not uncommon for different users on a given system to use different window systems.

To create a nice new configurable terminal window, type `konsole &' at the Unix prompt in an existing xterm window.

Adding the ampersand (&) to the end of a Unix command makes it run in the background. When a command runs in the background (as opposed to the foreground) you get the Unix prompt back so you can type another command if you wish to. In this way you can multi-task - have several applications running at once!

When you do work on csdev01, you are working on a compute server. You see the same machine and work on the same files whether you are working in our classroom, in the Moakley open access lab or from home. 

Unix and utilities

In this section you will experiment with some basic Unix commands, and learn a little bit about the way in which Unix organizes its file system.

Basic Unix directory/(folder) structure

Like most file systems, Unix's is tree-structured. The very top or 'root'  of the file system is named `/'. As a user on the system you have a home directory, where all your files are stored. To find out where your home directory is, type

echo ~ When I do this, I find out that my home directory is /home/bscstaff/jsantore. This means that my home directory jsantore is located in the subfolder bscstaff, which is a subdirectory of the home folder, which is an immediate subdirectory of the root directory (which is, as mentioned above, designated by `/'). " /home/bscstaff/jsantore" is a path which describes how to get from one directory (in this case the root directory) to another (in this case my home directory). A path can either be absolute (starting at /) or relative (starting at the current directory). Every directory has two special entries, `.' and `..'. The entry `.' refers to the directory itself, and `..' and refers to the directory's parent directory (i.e. the directory of which this one is an immediate subdirectory). The root directory is the only directory in the file system which does not have a parent directory. (Actually, this is not quite accurate. If you inspect the root directory you will find that there is a `..' entry. The parent of the root directory turns out to be the root directory itself!)

Getting started with Unix

Below I have listed some basic Unix commands. Read the description of each, and carry out any exercises given. Page number refer to page numbers on the handout given in class.

*ls - This command gives a listing of the files in a directory. Without any arguments, it provides a listing of the files in the current directory, and is therefore equivalent to `ls .'. If you specify a directory using a path, ls will respond with a listing of the contents of the specified directory. Try typing ls at the Unix prompt. (note for dos users this is similar to the dir command)

*cd - This command changes the current directory. Without any arguments, it changes the current directory to your home directory, and is therefore equivalent to `cd ~'. If you specify a directory using a path, cd will set the current directory to the specified directory. 

*pwd - This command gives the current or present working directory. Unless you have changed your working directory since logging in, typing pwd should return your home directory. Also try using the two commands together, try: ls ; pwd.

*piping input and output - It is possible to make the output of some command be the input of another command. This is done by creating what is known as a pipe between the two commands

*To give you an idea of how pipes can be useful, consider that there are times when the output you are asking for takes up more than one screen length. When this happens, the information simply flies off the screen. (for example try the command 'ls -l /usr/bin' to see this happen)  If your windows do not have scroll bars, you have lost the information that is no longer on the screen. Wouldn't it be nice if you could send the output of the command to some utility program which displays a screenful of information at a time

*Fortunately there is such a utility program, called more. For example, to pipe the output of ls to type `ls | more'. The vertical bar (|) is the pipe. 

*redirecting output. Sometimes it is useful to have the output of your command go into a file rather than onto the screen.  try the following example. Type

echo "Hi there!" > temp

The echo command normally prints to the screen whatever you type. (Try typing echo "TEST" to see how echo normally works). With output redirection (indicated by >) this does not happen. Instead the output of the echo command was redirected into a file named temp. If you list the files is the current directory, you will see an entry called temp.

*more & cat - Now we want to see what the file temp contains. We can do this many ways. The first way is to use more as described on page 17, or with cat as described on page 18. Try either and see what the contents of the file named temp is. 

*Using wildcards - Wildcard characters are used in patterns to match filenames. For example, the wildcard character `?' matches any single character. Hence, the filename pattern b?t matches any filename which is three characters long, whose first character is the lower case letter `b' and whose last character is the lower case letter `t'. Examples of filenames which could match this pattern are: bat, bbt, bct, and b1t, among others. Another important wildcard is the '*' wildcard. It will match zero or more characters. So W* will match any filename beginning with a capital 'W'

*man - The man command (short for manual) brings up a manual page (help screen) for a specified command. You can also get a help page about man itself by typing man man. Try
man passwd | col -b > ~/my.password.manual

This will place a copy of the man page for the passwd command in your home directory in a file called my.password.manual.

Exercize 1(25%)

Setting up your account: 

You will need to do two things to setup your account for this class. First change your password to something that you can remember

the passwd command is used to set your password. It is a command line program but is a fairly standard interface. You are first prompted for your current password, then you will be promted to enter and then reenter your new password. Remember that you will not see any characters echoed while you are typing passwords.

Second you need to setup your editor. (more about it below - for now we will just set it up)

use these commands to set things up

mkdir .xemacs                           (that is dot-emacs in case your font is small)

cp /home/bscstaff/jsantore/.xemacs/custom.el .xemacs

the spaces and the dot characters are all important.

There is nothing to submit for this part. Part 2 below will include a check to see that you did this part as asked.

Exercise 2 (25%)

Do the following exercise. You will hand in the result of doing this exercise. In order for your submission to be graded correctly you must follow the instructions given precisely, in the order given, and must not do anything extra.

Make sure your present working directory is your home directory. If it is not, issue a command to make your present working directory your home directory.

* Redirect the output of the pwd command to a file named `Exercise1a'

* Redirect the output of the ls -aR command to a file named `Exercise1b' (note capitilization matters!)

* Create a file named `Exercise1c' whose contents is the manual page for the finger command.

* Create a listing of all the files in /usr/bin which begin with same letter as your last name (in lower case).  Redirect the output of this command to a file named file named `Exercise1d'.

* Create a file named `Exercise1' which consists of the contents of the files `Exercise1a' through `Exercise1d', in that order.

Directories and files

Next is a list of some fundamental commands which allow you to manipulate and organize files in a Unix file system. Read the description of each, and carry out any exercises given.

*mkdir - This command creates the specified subdirectory. (Often called a 'folder' in todays more Machitosh-influenced discussions.)

*cp - This command copies a file to a new location, leaving the original unchanged. Type

cp temp anotherTemp
How many files does ls report now?. ( use man cp and look at the -r and -i flags to see more ways to used cp)

*More fun with ls - Try using ls -l to see lots of information about the files, ls -F (thats a capital F) to see a '*' after the executable files, and a '/' after all of the folders.

*mv - This command moves a file from one location to another. (this is how you rename in unix unless you are using a gui) A directory is just a special type of file to Unix, so we can rename the directory we just created before by moving it to a new location. Type

mv NewDirectory MyDir to rename the directory. Type `ls'.

*rm - The command rm removes a file. Type `rm temp' followed by `ls'. How many files does ls report now? Type `rm anotherTemp' followed by `ls'. How many files does ls report now? Read more about rm by reading the man page if you like.

*rmdir - This command removes the specified subdirectory. Type `rmdir myDir'. 

*Locate if you are looking for a file and forgot where you put it, try using the locate command. type 

locate finger to find all of the references on the system to the finger command (which can tell you who is logged into eagle at the moment)

Exercise 3 (25%)

Do the following exercise. You will "hand in" (by electronic submission) the result of doing this exercise. In order for your submission to be graded correctly you must follow the instructions given precisely, in the order given, and must not do anything extra.

* Make a new subdirectory of your home directory named `Lab1', and make it your current working directory.

* Redirect the output of the pwd command to a file named `Exercise3a'

* Move (don't copy) all the files from the parent directory which start with Exercise to the current directory.

* Type `echo "!!" > Exercise3b' (do this immediately after the previous step without any other commands in between - the point is to make sure you moved and didn't copy the file - following directions you see.)

* Create a directory listing of the current directory which shows at least the name, the size, and the permissions for all files (including hidden files). Redirect the output to a file named `Exercise3c'.

* Create a file named `Exercise3' which consists of the contents of the files `Exercise3a' through `Exercise3c', in that order.

* Submit the file `Exercise3'.

Creating a file

 In lab 2 you will be creating and editing files using a quite powerful editor called xemacs. Xemacs allows you to develop, compile and run a javas program all from within xemacs. Unix also has simple text editors like MS-DOS edit. There are lots of ways to create a file on a unix system, but since you will use xemacs most of the time, lets start there.

Start xemacs by typing 

xemacs & 

at the command line. Remember '&' means roughly "give me my prompt back while running this program"

Now you are staring at xemacs' 'scratch buffer' this is the buffer that xemacs doesn't care about and assumes you don't either. If you quit xemacs without saving whats in the 'scratch buffer' xemacs will assume that you don't want to save it and happily quit. Therefore you almost never want to write anything there. You will want to open a new file and start writing there.

xemacs is a very old program and decends from an even older program: emacs. These programs predate windows editors and their machintoshinpirations and use a different set of terms. 

Lets create a new text file using xemacs (something you will have to do for all of the labs to tell me who you are and what you did in the lab)

First lets go to the file menu, click on the file menu and you will see your opions. You'll note that there is no "new file" option. Instead you will choose the "open" option from the file menu. You will get a dialog that looks like this:
the xemacs file open dialog

You'll notice that the top part of the dialog is divided into two, the left side show the folders you can choose to move to (again this of the '..' folder the same as the up arrow folder in windows.) While the right side shows the files that are in the current folder. 

But we want to create a brand new folder so take a look at the part down at the bottom of the dialog where you see the text: 'Find file:" If you want a new file, just ask xemacs to find a file that doesn't exist yet, xemacs will create it for you. In this case create a file called Exercise3.txt by typeing that name into the Find file part of the dialog and pushing the ok button. 

You are now looking at the new file in xemacs. It should look something like this:

xemacs with the file Exercize3.txt open

You'll note that the name of your file is on the tab visible above. If you make a change to this file and then try to quit xemacs, the program will ask if you really want to save first before you close. Now put the following information into the text file

* Your first name

* Your last name

* The month in which you were born

Now you can save your file by choosing <file><save> or pushing the save button and you can quit from xemacs.

Printing files

While it is best to debug your programs on the computer, sometimes you might want to print something out, csdev01 does have printing capabilities.

This group of commands are useful to know when you wish to print a file to a printer.

lpr - The lpr command is used to submit a file or a set of files to a particular printer for printing. If you print from csdev01, the job will print on the eagle printer in the moakley open access lab.

The lpr command creates a print job, which is entered into the specified printer's print queue. A print queue is a list of all the jobs that are waiting to print. Jobs are order by the time at which they were placed in the print queue. A print queue works much like a queue at a bank teller.

*mpage - The mpage command can be used to print a file with multiple (logical) pages on one sheet of paper. You should use this command rather than lpr whenever possible to prevent the slaughter of poor innocent trees. See the man page for details about the various options available.

Compression of Files

The zip utility is used to create zip files. To create a zip file named of all the files in the directory named myDir type,
zip -r myDir

To extract the contents of the zip file (the directory bar with all its contents) type,

If you do this in the same directory from which you originally created the zip file, the contents of foo will be overwritten by what is in the zip file. (for more information read the man page by using man zip)

Exercise 4 (25%)

put your solution to exercises 2 and 3 into a folder and zip it up into a single zip file using the instructions above.

We will be using an online submission system on the csdev01 server itself this semester. Since this is the first semester I've used it, I'll be having you all submit in class and walk you through that first submission. You need to have parts 1-3 done before the beginning of class one week from now.

Due date


For this submission first 

make sure that Exercise3.txt is in your zip file. 

zip -r <your zip file name> Lab1

Now move into the directory with the submission system. (I'm looking into a way to skip this step)

cd /home/bscstaff/jsantore/submission/g2/oss



at that point. This will bring up a graphical submit window that I will walk you through.

This lab is Due at the beginning of class one week from its assignement (feb 7th for the Day students, Feb 6th for the evening students.)

Many Thanks to some of my former University at Buffalo colleagues who first developed the original version of this lab.