Lab 1

Introduction

In this first lab you will be introduced to the computing environment in the Baldy 21 lab. 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 not expect to finish all of these exercises during the allotted lab time. You should plan to return to the lab during open lab hours (hours when the lab is open but there are no formal labs scheduled) to complete your work.

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


Objectives

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

Be sure you completed the preparatory work outlined in the Lab 1 Prep Work.


Lab Tasks

Your instructor has briefly gone through the tasks listed below during lecture to help prepare you for this lab. You must now carry out each of the following tasks on your own in the lab setting. Chapter references are to the Unix book you should have brought with you to the lab.

Logging in - Connecting to the system

Your first lab task is to log in to your CSE computer account. Your CSE account is valid on the computers in Baldy 21. This account is separate from your UBUnix account.

Unix is the name of the operating system that is running on the machines in the Baldy 21 lab. 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).

The Common Desktop Environment (CDE) is a window system, or graphical user interface (GUI), to the underlying Unix operating system. CDE 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.

The default windowing system in Baldy 21 is the CDE.  You will see a graphic "wallpaper" in the background and also a large area at the bottom of the screen with the date, a clock, and other icons like a filing cabinet and a mailbox.  The background section is called the "root window".  You will also be given a mostly blank window on the screen that has a blinking cursor after some text and a > symbol.  The > symbol is called a prompt.  You will type commands into the prompt to get the Operating system to perform various tasks for you.  

If you feel you do not have this type of screen or your screen looks different from your neighbors, you can ask the TA how to log on using the CDE.

At this point we are going to cover how to log out of the system.  To log out of the system, first be sure to save any open files, then position the mouse pointer on the root window, click the right mouse button, and move down to left click on "Log Out".  There is an EXIT icon next to this menu selection.  You will probably receive a message telling you your home session has changed and will not be saved.  It is fine to hit OK at this point.  However, any files that have changes in them must be saved before clicking OK or the changes will be lost.  Try this now. Once your have successfully logged out, log back in to your account. Remember to never leave the lab without logging out, even if it is "just for a minute"!

Spend a moment getting comfortable with the CDE Environment.  To move a window with a title bar (such as one of the xterms), click and hold the left mouse button in the middle of the title bar and drag it to a new position. If you click on the small buttons in the title bars of the windows, different things will happen:

To create a new xterm window, type xterm & (or dtterm &) at the Unix prompt in an existing xterm window, or position the mouse pointer on the root window and click the right mouse button.  A menu will appear.  You will select the Hosts submenu and select the "This Host" option.  

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!

The files which you create are stored on a machine called a file server, which is accessible from all of the workstations in the lab. In other words, it doesn't matter which workstation you log in at, you will be able to access exactly the same files. The file server for the Baldy 21 lab is called everest.cse.buffalo.edu, or just everest for short. This file server shares its files with a system called yeager.cse.buffalo.edu (yeager), which you can log into from other places around campus and work on your CSE assignments.

Changing your Password

It is a good idea to change your password from your default password to something else. You should change your passwords often to help keep your account secure. You must never share your account password with anyone (including your friends and classmates). Read the section in Chapter 1 (pages 7-8) about changing your password. Passwords can only be changed while logged into hadar.cse.buffalo.edu. This is the only operation that you should do while logged into hadar. The rest of your work for this class should be done logged directly onto your machine.

Because your CSE account is separate from your UBUnix account, changing the password on one account does not automatically change the password on the other. You should change passwords on both accounts on a regular basis.

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 structure

Like most file systems, Unix's is tree-structured. The 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/csefaculty/adrienne. This means that my home directory adrienne is located in the subdirectory csefaculty, which is a subdirectory of home, which is an immediate subdirectory of the root directory (which is, as mentioned above, designated by '/'). "/home/csefaculty/adrienne" 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!)

Note that the ~ character actually means your home directory, so you are asking the system to "echo" your home directory.

Getting started with Unix
Below I have listed some basic Unix commands. Read the description of each, and carry out any exercises given.
  • 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. Do the other examples on the ls pages (pages 9-10).

  • 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. Do the examples of using cd on pages 11-12.

  • 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. Do the examples of using pwd on page 13.

  • 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. 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 of the directory /util to type ls /util | more. The vertical bar (|) is the pipe. See page 14 for further discussion of using | more to see a listing one screen length at a time.

  • redirecting output - Pages 15-16 talk about redirecting output to a file. Read over this section, and try the following example. Type

    whoami > temp

  • more, less & 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 18, or with cat as described on page 19. 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. Another wildcard that will be useful is the * this character, which matches multiple characters. Review page 17 for the basic use of wildcards.

  • man - The man command brings up a manual page (help screen) for a specified command. Let's get the man page for the finger command by typing man finger. Also try the examples given for man on pages 22-23.

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. Follow the example on pages 26-27 to make your own subdirectory named NewDirectory.

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

    cp temp NewDirectory

    How many files does ls report now? Look at the examples on pages 30-31 for more ways to use cp.

  • More fun with ls - Pages 32-33 talk about the different ways you can use ls to get different information about files. Figure 2.1 on page 32 will help those who have not used Unix before understand what gets displayed to the screen when you type ls -l at the prompt.

  • mv - This command moves a file from one location to another. For example,

    mv temp notsotemp

    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. Now type ls to see what has happened.

  • rm - The command rm removes a file. Type rm -i temp followed by ls. How many files does ls report now? Read more about rm on pages 35-37.

  • rmdir - This command removes the specified subdirectory. Type rmdir myDir. Read pages 38-39 for more examples of removing directories.

  • find and ln - The sections on find and ln are interesting to read about - especially when you are looking for a file and can't remember which directory it is in. Read pages 40-46 for more information about these two commands.

Compression of Files

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

zip -r foo.zip bar
To extract the contents of the zip file foo.zip (the directory bar with all its contents) type,
unzip foo.zip

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. Chapter 13 talks about different ways to compress and decompress files. The zip utility is discussed on pages 290-291.

The command shell

Chapter 3 of the Unix book talks about shell command interpreters (often referred to as just shells). You interact with the shell when you type commands at the prompt. You should read this chapter. It is important to know that there are different shells available and understand what some of the differences are amongst these various shells. This chapter also leads nicely into Chapters 8, 9 & 10 that deal with running and writing basic programs that can work with the shell and also with configuring the shell. These topics are a little more advanced than you need for this course. When you are ready to delve deeper into the world of Unix these chapters are a good place to start.

Creating a file

Chapter 4 of the Unix book mentions two editing programs you can use to create and edit files. This semester, we will develop our Java files in an editor called Eclipse, which is an environment designed specifically for creating programs. The programs in Chapter 4 are simple text editors, like MS-DOS edit. We will use pico for this exercise and you will learn more about Eclipse next lab.

Exercise 1 (35%)

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.
  • Copy the skeleton files for this lab located in the directory /projects/CSE115/Skeletons/Lab1Skeleton.zip
    into your home directory (~)

  • Unzip the Lab1Skeleton.zip file. Notice that a new directory named Lab1 has been created by unzipping the Lab1Skeleton file.

  • Change directories into the Lab1 directory.

  • List all of the files in this directory and notice that inside the Lab1 directory are two more directories.

  • Change directories into the Sub1 directory.

  • View the contents of the file named MyName.txt. If the file does not contain your name, you will need to edit the contents appropriately. You should use the program pico to help you do this. The pico program is discussed in the Unix book in Chapter 4 pages 72 - 77.

  • Change into the Sub2 directory by typing the cd ../Sub2 command.

  • Move the file named Lab1.txt directly into the Lab1 directory by using the move command and the .. (parent directory).

  • Create a file using pico named Command.txt in which you will type the command you just used to move the Lab1.txt file. Save this file in the Lab1 directory.

  • Delete the Sub2 directory.

  • Zip the Lab1 directory and its contents to make a file named Lab1.zip. Submit this file now that you have completed Exercise 1.

How do you submit files? In general you submit files using the submit command, which has the following format for CSE115:

submit_cse115?? filename
where `??' is your section. Your section is the recitation section of the course such as a2 or b3. The filename is the name of the file you wish to submit. Let us suppose that you are in the b2 lab section. Since you want to submit a file named Lab1.zip, you should then type
submit_cse115b2 Lab1.zip
(Of course if you are not in section b2 you need to substitute b2 for your actual lab section.)
If the submission worked properly you should get a message saying
Submission of "Lab1.zip" successful.
If you are in CSE503, you would submit to the recitation you are attending. Most of you are attending A4, so it would be submit_cse115a4.

You can also use the submit inspector on the resources page of the course web site to verify that your submission was delivered properly. If you do not get this message, ask a lab assistant for help.

 

Exercise 2 (20%)

Using the rm command without the -i flag can lead to disasterous results, especially if you execute the command and have a typo. Suppose you wanted to delete all files with the file extension .txt (rm *.txt), but when you typed the command, you accidently typed rm * and now you have deleted all the files in the directory, including the files for the project that is due in 15 minutes for CSE 115!

To help avoid these calamities, we are encouraging you to alias the rm command to actually execute the rm -i command. This way, the system will prompt you to ensure that you really want to delete the files you requested. You can read about the alias command on pages 184-185.

You can alias as many commands as you wish, but for the purposes of the exercise, we are most concerned with you alias-ing the rm command and a connection to the other system we will be using this semseter, coldplay. You can do this by creating a .alias file using pico. In this file you can place any aliases that you wish to create for yourself. Save this file in your home directory.

For our systems, you format your alias command like this:

alias rm 'rm -i'

There is also one other important alias you will need for completing the labs for the rest of the semester and that is a way to log into the machine named coldplay where Eclipse lives. You should add the following alias to your .alias file as well.

alias coldplay 'xterm -e ssh -X coldplay &'

Next, create a backup of your .cshrc file by copying the file to a file named .cshrcBack. Creating a backup copy of a system file is always a good idea before attempting to modify it. This way, if you do not like the settings you changed, you can simply revert back to the original settings before the changes. Open the original .cshrc file and at the bottom of the file type:

source ~/.alias

Save and close the file. Next time you log into everest/yeager, your aliases will take effect.

Printing files

These batch of commands are useful to know when you wish to print a file to a printer.

 

Web browser

Start the Netscape web browser by typing netscape & at the Unix prompt. You can access another web browser by typing firefox & at the prompt as well. If you have not already done so, visit the course web site, whose URL is,

http://www.cse.buffalo.edu/faculty/adrienne/SP2006/cse115
and browse around to get a feel for the types of information available to you. You are expected to check the main page of the web site for announcements on a regular basis.

E-mail

Since you have a UB-IT account (i.e. an ACSU or UBUnix account) you also have an e-mail address @acsu.buffalo.edu. You cannot receive e-mail at this account until you enable it (even though you can send e-mail from this account without needing to do anything special). You should have enabled your ACSU e-mail account before coming to your lab session. If you have not already enabled this e-mail account, do so now by visiting http://mailcluster.acsu.buffalo.edu/newuser.html, entering your UB-IT name and clicking the "Submit" button.

The CSE e-mail system is separate from the main UB e-mail system. You can choose to maintain two separate and parallel e-mail systems for yourself (make sure you read e-mail at both sites). An alternative is to designate one as your primary e-mail system, and to forward your e-mail from your secondary e-mail service to your primary.

Either e-mail service can be your primary one. If you wish all your CSE e-mail to be forwarded to your UB e-mail system, create a .forward file in your yeager account, which lists those e-mail accounts to which you wish to have your e-mail automatically forwarded. Make sure your CSE e-mail address is not listed here!

If you wish all your UB e-mail to be forwarded to your CSE e-mail address, you must visit http://mailcluster.acsu.buffalo.edu/filter.html to set up mail forwarding.

Make sure you forward your mail in only one direction!

You can, if you prefer, forward e-mail from both your UB accounts to some other account, if you, for example, prefer to read your e-mail via your hotmail, aol or other commercial system. Creating the .forward file is discussed on page 241.

For reading mail in the Baldy 21 lab you may use pine or elm, or any other mail reader you might have access to. (Pine is slightly more user-friendly and has facilities for reading news as well). Run pine (or elm) by typing pine (or elm) at the Unix prompt. Then, follow the instructions for reading and sending email in Chapter 11 for whichever program you choose.

Also included in Chapter 11 is information on how to make a signature file. A signature file contains text which is appended to the end of each e-mail you send, and is typically used to give contact and affiliation information.

 

Exercise 3 (25%)

Send an e-mail to the grading TA for your section. (See the table below for who your grading TA is.) Make sure you send a copy to yourself by including your e-mail address in the list of recipients in the "To:" or the "CC:" line. It is strongly suggested that you use the email program pine for this exercise. The email should be received from your cse mail address, no other email addresses will be accepted. (Resist most strongly the urge to send a copy of this e-mail to your lecture instructor or the teaching TA that is in the lab with you now.) The subject of your e-mail must be: `CSE 115: Lab 1 your name and person number'. For example, `CSE 115: Lab 1 Frodo Baggins 13572468'.

The contents of your message should describe, in 50 words or less, why you want to take CSE 115. You should also create an attachment to this email that is the file you created named .alias that contains your defintion of the rm alias and any other aliases you wished to create. Verify that you can read the mail, once you receive it. Exit the mail program when done.

Recitation Section
Grading TA

A1

Yang Wang
A3
Xujun Peng
A4
Yang Wang
B1
Xujun Peng
B2
Yang Wang
B4
Xujun Peng

 

Miscellaneous topics

If you wish to explore Unix further you are encouraged to read the Unix book in its entirety.

Chapter 5 deals with some of the security features implemented on Unix. It talks about how users are allowed access to some files, but not to others. This is important especially if you are creating a webpage. In order for everyone to view your page, you need to make sure that the files are readable to everyone. It also discusses groups and group permissions to files - so that everyone does not have access, but rather only those members of a specific group.

Chapter 6 deals with manipulating parts of files, and comparison between them.

Chapter 7 talks about getting information out of the system, such things like who else is on the system at the same time you are. All of these chapters have useful information in them, but this lab would get much longer than it already is if we went through every page. You are encouraged to read these chapters and learn the material in them.

Chapter 12 talks about some basic issues related to the Internet, Unix, remote systems, how to communicate with users and how to tranfer files. This book suggests using lynx to surf the web. Lynx is a text-based browser available on our systems. I would, however, strongly suggest that you use a graphical web browser instead. The only currently supported browswers on our Unix system are Netscape and Firefox.

Chapter 14 deals with installing software onto the system. At this time, you will not need to do this, all of the software needed for this class has already been installed on the system for you. Chapter 15 talks about some handy utilities available on the Unix system, like a calendar (we have a graphical version called xcalendar; also useful is plain old cal), a calculator (we have a graphical calculator named xcalc), spell checkers, and history keepers. This is a valuable chapter for making working with Unix more enjoyable. Chapter 16 talks about some more advanced Unix tricks that are nice to know, such as mail sorting and multiple file replacement.

Appendix A is a recap in short tabular form of all the commands discussed in the book - a good quick reference guide. Appendix B talks about the main file structure for a Unix system. Appendix C gives a list of many Unix commands and the flags that can be used on them. It also gives a description of what all of those things do. For example, in the command ls -l, the -l is called a flag (or option) on the ls command.

 

Use the Tools You Have Been Given

One of the most important lessons that you can learn as a computer scientist is how to make the resources available to you, work for you. The same is true of the resources of this class. Information is always given during lectures and recitations and you are most strongly encouraged to attend all lectures and recitations throughout the semester. There is a wealth of information available on the course website to help you with the material of this course.

Another resource that is available to you is the staff of the course, which includes both the instructors and the teaching assistants. There are office hours available at many times throughout the week for you to go and receive extra help on an assignment or simply have some questions answered about the week's material. No appointments are needed to come to office hours.

 

Exercise 4 (20%)

To ensure that you will be able to use the resources of this course, you will spend some time this week visiting office hours. You will also use the resources of this website to help you on your journey. First, follow this link to find the Lab 1 attendance form. You should print out the form. Follow the directions on the form to complete Exercise 5. This form is due to be handed in at the beginning of your next recitation section. Note that the electronic portions of this lab are due to be completed by 11:59pm the night before your recitation meets next week.


Due dates

You have one week from the meeting of your lab to submit your solution. For example, if your recitation meets on Wednesday, January 25th then you must submit the lab by 11:59 pm on Tuesday, January 31st. The due dates are summarized in the table below.  If you submit more than once, the later submission will simply overwrite the previous one.

 

Date of lab Due date for electronic submission
Tuesday, January 24 Monday, January 30
Wednesday, January 25 Tuesday, January 31
Thursday, January 26 Wednesday, February 1
Friday, January 27 Thursday, February 2