Computer Science 220
Assembly Language & Computer Architecture

Fall 2011, Siena College

Lab 0: Get Real: Unix Basics
Due: 11:59 PM, Monday, September 12, 2011

The purpose of this first lab assignment is to acquaint or reacquaint you with the Unix systems in the CS department and to help you to learn how to run a C program in those environments. None of these tasks is intended to be hard, but if you don't have much Unix experience (and you probably don't), they could be. So...ask if you are not sure what to do! Plenty of questions are expected. I would like to make sure everyone can do each part of this lab, so you may need to take turns using the lab PCs or some of you may need to work in Roger Bacon 350.

Logging In and Getting Started

We will be using the Unix-based systems within the Computer Science department extensively this semester. For the first part of this lab, you will log into and familiarize yourself with your CS Unix account.

Log into a Linux system in Roger Bacon 306. Starting this semester, our Linux systems operate on VMWare virtual machines under Windows. To get into Linux, you (sadly) must first log into Windows. One you get your Windows desktop, launch the VMWare Player. Accept the license agreement if asked, after which you should get a "Welcome to VMWare Player" window. From here, choose "Open a Virtual Machine". The machine you should open is on the C:
drive, in the VMDebian6 folder, and is called Debian_6_Squeeze. After choosing the file, you should be able to choose "Play virtual machine" to "boot up" your Linux system inside VMWare. You'll be asked a few questions on the first bootup, but eventually you should boot into Linux in the VMWare window.

Once you are in, the system will present your desktop for a Graphical User Interface (GUI) called Gnome. You'll need to log in again (since your Windows login credentials have no meaning to Linux). The desktop you are presented with should be reasonably intuitive to use. Experiment with the menus to find useful and familiar applications like the Firefox browser. Though with the virtual machine setup, you may find it more convenient to run your browser on the Windows side.

Logging Out

Just as login took a few steps, logging out will as well. Close any windows you have open in Linux. Then choose "Shut Down" from the "System" menu. After a minute or so, your VMWare Player window should close and you can log out of Windows as usual.

The Unix Command Line

GUIs are nice, but they can be slow to navigate and too restrictive for a serious user. You will be spending a lot of your time in the Unix environment interacting with the system typing at the Unix shell, or command line. To open a window where you can access a Unix shell, select "Applications" then "Accessories" then "Terminal".

A window will open and you will be presented with a prompt. This is your direct interface to issue commands to the operating system. When you type a command here, the shell will execute the command on your behalf, print out any results, then reissue the prompt.

Of course, the command line is useless if you don't know what commands it understands. You will learn about several important commands in this lab and many more throughout the semester. One of the most important is man - the Unix manual. Every Unix command has a manual page, including man. To see the manual page about man, type the command:

      man man

Navigating the Directory Structure

You have very likely used systems where files can be organized into folders. When accessing these kinds of structures from the command line, we usually refer to them as directories. Each program in a Unix system, including your shell, maintains the notion of a working directory. That is where the program will look for files unless instructed to do otherwise. You'll hear Unix users asking a question like "What directory are you in?" and the answer to this is your working directory.

When you first open a shell, your home directory is your working directory. In our environment, you should see the same files here that are on your "Z drive" in Windows.

The command pwd will instruct the shell to print your working directory. Try it. You can also list the contents of your working directory with the command ls. Try this as well.

The other important operations to navigate the directory structure are changing your working directory (cd), creating a new directory (mkdir), and removing a directory (rmdir).

Local and Remote Logins

In your shell window and in your home directory (note: you can always reset your working directory to be your home directory by issuing the command cd with no parameters), issue this command:

      uname -a > linux.txt

This will execute the command uname -a, which prints a variety of information about the system you are on, and "redirects" the output, which would normally be printed in your terminal window, to the file linux.txt.

Log in remotely to the Linux server, olsen.cs.siena.edu. Use a Secure Shell (ssh) client, either from the Linux command line or from elsewhere. Secure shell clients are standard on most modern Unix-based systems (including Mac OS X) and are readily available for Windows systems. You may also log into olsen from elsewhere on campus or, in fact, anywhere on the Internet. Once logged into olsen, you will have access to the same files you have in your account on Roger Bacon 306 Linux systems.

In your terminal window that is logged into olsen, execute this command:

      uname -a >> linux.txt

This is the same as what you did on your local Linux system, except that we are using >> to redirect output. The difference is that instead of creating a brand new file linux.txt (thereby overwriting the previous contents of the file), the command will append the output of uname -a to the end of the file linux.txt.

Look at the contents of the file linux.txt. Can you guess what some of the information in these files might mean?

The Emacs Editor

Emacs (emacs from the Unix command line) is a powerful text editor. You will want to become familiar with it. Identify the function of and experiment with these Emacs commands:

 
C-x C-s   C-x C-c   C-x C-f   C-x C-w   C-g   C-a   C-e        
C-d       C-_       C-v       M-v       C-s   C-r   M-%

C- before a key means hold down Ctrl and hit that key. M- indicates the "Meta" key, which on most systems is Esc. To issue a Meta command, hit the Esc key, release it, then hit the key for the command you wish to issue. Use the keystrokes rather than the menus. It will save you time in the long run!

Include a brief description of each Emacs keystroke in a file unix.txt. Use Emacs to create and edit this file.

Learn these commands - you will use them often. Hints can be found in the Unix and Emacs web pages linked from the course website. Ask others in the lab if you're not sure how to do something in the Unix environment. Share your tips and tricks with each other.

Unix Commands

Identify the function of and experiment with these Unix commands (a few of which you have already used):

 
ls    cd      cp      mv     rm     mkdir   pwd
man   chmod   cat     more   grep   head    tail
ln    find    rmdir   wc     diff   tar     touch

Running a Simple C Program

Copy the C program here that computes the late penalties for this course to your account. Compile and run it, redirecting your output to a file late.txt.

Assuming you have copied the program into a file late.c, you can do this with:

	gcc late.c -lm
	./a.out > late.txt

Submission

To submit this lab, place all of the files that you are to turn in (and nothing else) into a directory, change to that directory, and create a "tar file" to submit.

tar cvf unixintro.tar *.txt ls.out

This will create a file intro.tar in your directory. Send this tar file as an attachment to jteresco AT siena.edu by 11:59 PM, Monday, September 12, 2011.

Please include a meaningful subject line (something like "CS220 Lab 0 Submission") and use the exact filenames specified (for this lab and all semester) to make things easier when gathering your submissions together for grading. You don't want to annoy your grader with misnamed or missing files just before he grades your assignment. Please do not include any additional files, such as emacs backup files, object files, or executable programs.

Grading

This lab will be graded out of 15 points.

Grading Breakdown

linux.txt file 1 point
unix.txt command descriptions 3 points
unix.txt emacs descriptions 3 points
unix.txt other responses 3 points
late.txt 1 point
ls.out with correct directory structure 2 points
tar file creation 2 points