Getting Started with UNIX

UNIX is running on the Sun computers in clusters around campus. To start working in unix you must first enter your acpub id and password on the login screen. Once you've done this, UNIX will start and present you with a number of windows, including command prompt xterm windows. UNIX contains lots of commands, a few important ones are introduced here. More thorough information on unix is summarized on an OIT web page.

To enter a command, type after the prompt in one of the xterm windows. You should see a prompt that may look similar to

    [1] rodger@teer22
except rodger should be replaced by your login-id and the number and machine name may be different. If you make a mistake when typing a UNIX command, use the delete key or the arrow keys to correct it.

Environment for Compsci courses

If you're using your acpub disk space and Unix environment for programming in a Compsci course you need to make the environment friendly for programming. The simplest way to do this is to run a script we've made that modifies some files. Type the command below, but replace cps100 with the name of your course, e.g., cps006, cps006x, cps108, etc. Run the command from your home directory which is where you'll be when you first log in to the system.

   /afs/acpub/project/cps/bin/setup cps100

This command creates a cpsxxx directory, sets up permissions for the TA/Professor to view files you create in this directory, and sets up your PATH so that submit commands, eclipse, and other programs will be found when needed. It also makes xemacs (and emacs) nicer for writing code.

Creating and Traversing Directories

To do your programming you will either need to create a directory for a new project or find the directory for an existing project. You can do this using a small set of basix UNIX commands. Type the command pwd to print the current directory. Sessions begin in your main (or "home") directory. This should look like /afs/acpub.duke.edu/users/r/o/rodger, except your acpub id will replace the rightmost word.

The next basic command is ls, which displays all the files and directories located in the current directory. This tells you which files you can open and the directories to which you can navigate.

The cd command allows you to navigate through your directories. If your home directory contains a public directory, you can enter it by typing cd public. To go back a directory, type cd .., where ".." represents the parent of the current directory. Finally, note that you can type cd by itself at any point to return to your home directory.

The mkdir command allows you to create a new directory, to store a project, for example. Say you want to create a directory called words. First, navigate to the directory you want to be the parent of words using "cd." Once you've done that, type mkdir words. Then type cd words to enter your new directory and begin working.

The cp allows you to copy files. The general syntax for using this command is cp originalfilename copyfilename . For example, if you have a file named wordsorig.cpp and want to create an exact copy named wordscopy.cpp, type the command cp wordscopy.cpp wordsorig.cpp. You can also copy files across directories. The command cp cps006/words1/words.cpp cps006/words2/words.cpp navigates to the words1 directory, makes a copy of words.cpp, navigates to the words2 directory, and writes the copy. Note: you can use "." in file paths to represent your current directory. Suppose you are already in the words2 directory. You can achieve the same result as the above command by typing cp ../words1/words.cpp . (note that the trailing period in the command is not the end this sentence, but to indicate the current directory).

Using xemacs

Starting xemacs

To type in your program you need to use an editor. To use the editor xemacs to create a new file for your program type the command
 xemacs & 

Alternatively, to open an existing file named (for example) words.cpp, type the command

 xemacs words.cpp & 
An xemacs window should appear (please be patient!). You can use the arrow keys and the mouse to move around in the xemacs window.

Loading, Editing, Saving Files

In general, while working in unix, you should always have an xemacs window open. Unless you are logging off, there is seldom a reason to quit xemacs. You can, however iconify (make small) the window by clicking the mouse on the dot-button in the upper right of the window. This works for any window. Double-clicking on an icon opens that application.

Until you save your file, it is stored in a temporary buffer (the region in xemacs in which you are typing). When you believe the C++ program is correct, save it by clicking the Save button at the top of the xemacs window (or click File and then select a Save option). A message that the buffer has been written should appear in the minibuffer.  You should save your program often to ensure none of your changes are lost inadvertently. 

Compiling a C++ program

A compiler transforms your C++ code into machine readable code the computer can understand. Programs can be compiled from within xemacs as well.  To compile from within xemacs:
  1. Use the Compile option under the Tools menu.
  2. The command make -k, which appears in the minibuffer, is the default compile command. You must edit this command so that if you are compiling words.cpp, for example, it reads make -k words. Then hit return. It may take a while for the program to compile, but you should see an xemacs sub-window with an indication that something is happening.
  3. If there is a syntax error in the program, a message will appear in the *compilation* buffer. To get to the error you can click on the error with the middle mouse button. This will take your cursor to the line on which the error appears, so you can use it to cycle through multiple errors, fix them, and then recompile.

Running your program in UNIX

Once your program compiles it is very simple to run it. Return to an xterm window navigated to your project's directory. Type ls to check that your executable appears. If you have compiled words.cpp your executable will simply be words or words* (not words.exe). Run this program by typing words and pressing return.

Submitting in UNIX

When you submit in UNIX, your assignment ends up in the same place as in eclipse. Now, however, you must manually call the submit_cps006 program. The general syntax is
submit_cps006 assign_name *.cpp README
Note that the "*" is shortcut that means "all." When you submit "*.cpp," you are submitting all files with the "cpp" suffix. If you are submitting assignment 1, you would type
/afs/acpub.duke.edu/project/cps/src/submit/submit_cps006 assign1 *.cpp README
Finally, remember that, as in eclipse, if you submit more than once, include all your files in every submission. Otherwise, your assignment cannot be graded.