Computer Science 433
Programming Languages

Fall 2012, The College of Saint Rose

Program/Problem Set 1: Unix Commands
Due: 11:59 PM, Wednesday, September 5, 2012

In this assignment, you will learn some Unix commands, then implement them in the language of your choice (I assume this will be Java for most of you). You may work alone or with a partner on this assignment.

The Unix Command Line

To get started, log into mogul.strose.edu. In your favorite editor, create a document in which you will answer the questions you find in this section. Start by putting your name at the top of this document.

GUIs are nice, but they can be slow to navigate and too restrictive for some purposes. For some of our examples and assignments, you will be 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

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. The command pwd will instruct the shell to print your working directory.

Question 1: What is your home directory on mogul.strose.edu? (use pwd)

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

Question 2: What output do you see when you issue the ls command on mogul.strose.edu?

Other important operations to navigate and mofidy 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 (cs433 might be a good name), and a directory within that directory for this assignment (ps1 might be a good name).

Question 3: 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.

Look at the contents of the file linux.txt.

Question 4: What do you think this information 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   tar     touch

Question 5: Give a one sentence description of each command.

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

Show that this has worked by issuing the following command from inside of your course directory:

	ls -laR > ls.out

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

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

Question 7: Give three different ways to change your working directory to be your home directory. All likely involve the cd command, but will take different parameters. This may take a bit of investigation.

Create a "tar file" that includes your linux.txt and ls.out files by issuing this command while in your directory that contains those two files:

tar cvf unix.tar linux.txt ls.out

This will create a file unix.tar in your directory. Transfer this to the computer you're working on with a secure copy program like WinSCP or FileZilla.

Implementing Some Unix Commands

Your programming tasks are to implement clones of 3 Unix commands in the language of your choice:

File Copy
 

cp filenameA filenameB - copy the contents of filenameA to a file named filenameB; see the Unix cp command.

Note: if you write this in Java, you would instead issue the command

java cp filenameA filenameB

but it should behave otherwise like the Unix cp command.

Display File Contents
 

cat [OPTION] filename - display the contents of filename, where the options can be either (or neither) of:

See the Unix cat command.

Word Count
 

wc filename - find the number of lines, words, and bytes (characters) in filename.

See the Unix command wc.

Write a separate program for each of the above (that is, do not have a single program that tries to perform all of the functionality).

Your code should be commented appropriately throughout. Please also include a longer comment at the top of your program describing your implementation. And, of course, it should include your name.

Submission

To submit this assignment, send all necessary files (your document with the answers to the questions, your unix.tar tar file, and your program source files) as attachments to terescoj AT strose.edu by 11:59 PM, Wednesday, September 5, 2012.

Please include a meaningful subject line (something like "CS433 Program/Problem Set 1 Submission"). 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 25 points.

Grading Breakdown

linux.txt file 1 point
ls.out with correct directory structure 1 point
Unix command descriptions 3 points
other question responses 4 points
cat program correctness 4 points
cp program correctness 4 points
wc program correctness 4 points
Program documentation 2 points
Program efficiency, style, and elegance 2 points