Computer Science 220
Assembly Language & Computer Architecture
Fall 2010, Siena College
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.
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. If the computer is booted in Windows or shut down when you arrive, boot into CentOS (the Linux distribution we use).
Once you are in, the system will present your desktop for a Graphical User Interface (GUI) called Gnome. It should be reasonably intuitive to use. Experiment with the menus to find useful and familiar applications like the Firefox browser.
The Unix Command Line
GUIs are nice, but they are very 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, choose "Open Terminal" from the menu that pops up when you right-click anywhere on the desktop.
A window should open and you should 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.
When you first open a shell, your home directory is your working directory.
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
ls -laR > ls.out
Then move the file ls.out into the lab0 directory.
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 13, 2010.
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 10 points.
Grading Breakdown | |
linux.txt file | 1 point |
unix.txt command descriptions | 4 points |
unix.txt emacs descriptions | 3 points |
ls.out with correct directory structure | 1 point |
tar file creation | 1 point |