Computer Science 507
Software Engineering

Spring 2014, The College of Saint Rose

Lab 1: Unix Introduction/Refresher
Due: 6:00 PM, Monday, January 27, 2014

In this assignment, you will learn or refersh your knowledge of some Unix commands. You may work alone or with a partner on this assignment. However, if you work with a partner, please be sure that both team members are able to log into the Unix system and create the directory structure specified later in the lab.

You may ask your instructor and classmates for help as you complete this lab, but the work you submit must ultimately be your own (or that of your partner, if working in a group). If you are completely unfamiliar with Unix, don't hesitate to ask questions! On the other hand, if you have some experience, don't hesitate to help a classmate! None of these tasks is intended to be hard, but if you don't have much Unix experience (and it is reasonable if you don't), they could be.


Before you begin work on this lab, you should make sure you can log our remote-access Linux system (a separate account that needs to be set up if you have not used this system for a previous course).

Also, read over the description of the types of items you will encounter in our labs on the course home page.


GUIs are nice, but they can be slow to navigate and too restrictive for some purposes. You can often work much more efficiently by working in a Unix environment and interacting with the system by typing commands at the Unix shell, or command line. When you log in, 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

The Emacs Editor

Emacs (emacs from the Unix command line) is a powerful text editor, which is very good for programming in a language like C and for general plain-text editing. You will need to become familiar with it.

To try it out, you will use it to create your lab1.txt file that will contain your answers to this week's lab questions. For at least this lab, you are to create this file in your home directory on mogul.

Log into From PuTTY or similar Windows secure shell clients, just fill in the information on the connection dialog using for the host name and your username for the username.

If using ssh from a Terminal window on the Mac, and your username on is jcool, you would issue the command

ssh -l jcool

at the terminal prompt. Log in with your password. You should be presented with a prompt that looks something like:

[jcool@mogul ~]$ 

and mogul is now ready to accept your commands. More on those later.

Now open a second PuTTY or Terminal window and log into on that one as well.

In one of the windows, launch emacs on the file lab1.txt:

emacs lab1.txt

Emacs should start up, and present you with a text-based menu across the top (which we will purposely ignore), a large area where you can edit the file, and two lines of status information across the bottom.

Type your name and "Lab 1 Questions" in the Emacs window that is editing the file lab1.txt:

In the other window, launch another emacs session where you can type some text and then 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-k       C-y       C-x u

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(s) for the command you wish to issue. Use the keystrokes rather than the menus. It will save you time in the long run! Note: for some of these commands, a very small buffer (that is, the contents of the file you are editing) will not allow you to see what they do. So create a file with several screens full of text before you go too far.

Question 1: Complete your Emacs command descriptions in lab1.txt (4 points).

Directory Structure

It is always important, but especially so when working with the Unix command line, to know where the files in various directories (often called "folders" on Macintosh and Windows systems because of how they are visually represented in GUIs) you might be using are actually stored, and where and how those are accessible.

On, we find a standard Unix style environment. Each user has a home directory where only that user has permission to read and write files. Your home directory is the initial current directory or working directory when you first log in.

The working directory 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.

The command pwd will instruct the shell to print your working directory.

Question 2: What is your home directory on (use pwd)

Note: the lab questions for this week are worth 1 point each unless otherwise specified.

You can also list the contents of your working directory with the command ls.

Question 3: What output do you see when you issue the ls command on

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

Create a directory in your account for your work for this course (cs507 might be a good name), and a directory within that directory for this assignment (lab1 might be a good name).

Question 4: Change your working directory to the one you just created and issue the pwd command. What does this show as your working directory?

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.

Output Capture: linux.txt for 1 point(s)

Look at the contents of the file linux.txt with the command:

       cat linux.txt

Question 5: What do you think the information in linux.txt means?

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   scp     touch

Question 6: Give a one sentence description of each command. (5 points)

Using appropriate commands from the above list, move the linux.txt file you created in your home directory into the directory you created on mogul for your work for this assignment.

Show that this has worked by issuing the following command from inside of your course directory (but not inside the directory for this assignment):

	ls -laR > ls.out

Then move the file ls.out into the directory for this assignment.

Output Capture: ls.out for 3 point(s)

Using the Unix manual, your favorite search engine, or in discussion with your classmates, determine the answers to these questions:

Question 7: How do you change your working directory to be "one level up" from the current working directory? (Give the command.)

Question 8: Give two or three different ways to change your working directory to be your home directory. All likely involve the cd command, but will take different parameters. (2 points)

The C Programming Language

C is a widely-used, general purpose language, well-suited to low-level systems programming and scientific computation. We will not study it in detail in this course, but it is worth a bit of our time to see how to develop, compile, and run a simple C program in a Unix environment.

We will initially study it assuming you have Java experience, focusing on the features that make C significantly different from Java. Fortunately, Java borrowed much of its syntax from C, so it is not difficult for a Java programmer to read most C programs.

C++ is a superset of C (that is, any valid C program is also a valid C++ program, just one that doesn't take advantage of the additional features of C++). C++ adds object-oriented feautures. In this course, we will look only at C, not C++.

A Very Simple C Program

We will begin by seeing how to compile and run a very simple C program (hello.c) in a Unix environment.

See Example:

For you to run this, you will want to copy the example to your own directory. Create a directory called hello under your directory for this lab and copy the C file into that directory.

Change to that directory and compile and run it:

gcc hello.c

Things to note from this simple example:

Practice Program

Write your own C program named helloloop.c, much like the "Hello, World" example, but which prints some other message and prints it 10 times inside of a for loop. The C for loop is much like Java's for loop, except that the loop index variable needs to be declared before the loop. That is, a Java loop that looks like this:

for (int i=0; i<10; i++) {

would need to have the declaration of i outside of the loop:

int i;

// any other code that happens before the loop

for (i=0; i<10; i++) {

Make sure your program compiles and runs on mogul using gcc.

This program is worth 10 points.

Note: there are no formal "Programming Assignments" this week.


Before 6:00 PM, Monday, January 27, 2014, submit your lab for grading. Package up all required files into an appropriate archive format (.tar.gz, .zip, and .7z are acceptable) and upload a copy of the using Submission Box under assignment "Unix".


Grading Breakdown

Lab questions and output captures 20 points
Practice program 10 points