Lab 0
Getting Started With CS143

September 5, 2009


Welcome to the first lab in the CS 143 course. For this course, you are going to need a SEAS account. If you do not have a SEAS account, please talk to the front desk to get one set up ASAP.

On your desktop, there is a program called Secure Shell Client. This program allows you to ssh into the SEAS server in order to work on your files. This program is also available for download from the GWU Help Desk Homepage, so you can work from anywhere with an internet connection. Another such program is called PuTTY. For this course, you should do all your work through one of these two programs, directly on the server. We will cover how to do this later.

The server you will be working on this semester is referred to as hobbes. The Host Name is In the Secure Shell Client, click Quick Connect, enter in this name into the host name section, and put your SEAS user name in for the user name. Clicking connect will prompt you for your SEAS password.

NOTE: When you first log in, you will be in the ksh shell. This shell is not very user friendly. Type bash into the command line to change to the bash shell. This shell is more user friendly, allowing you to press the up arrow to reference previously typed commands.


  • Commands
  • Please review the list of commands above. They will be used throughout the semester. Note that the directory you start in when you log into hobbes is referred to as your home directory.

    Relative vs. Absolute Paths

    In Unix, there are two types of paths: Relative and Absolute. A relative path is a path that relies on your current location in the Unix directory structure. An absolute path is a path that is the same from any location in the directory structure. An absolute path always starts from the root (/) directory. For example, if I am in my home directory, the absolute path to my cs143 directory is
    while the relative path to it is just

    There are a few special path modifiers you can use. One is ~ which stands for the home directory. Another is .. which stands for the directory above the current directory in the file system tree


    Files and directories in Unix are protected by three sets of permission descriptors. You can view these using the ls -l command. The first column of the output indicates permissions. The first character of the permission set lists whether or not the item being inspected is a directory. The next three characters are your personal (u) permissions. The second set of three characters are for group (g) permissions. The final set of three characters are for others (o) permissions. Any file can have read (r), write (w), or execute (x) permissions. Full permissions are represented as rwx. When a permission is not granted, a - takes its place in the permission set.

    Text Editors

    There are several command line based text editors for your use. The most commonly used text editors are emacs, pico, and vi. If this is your first time using a command line based text editor, We suggest using pico. Emacs and Vi are somewhat more complicated. To open any of the editors, just type their name at the command line. In Pico, all of the commands are listed at the bottom of the editor. The ^ represents the ctrl key. View the below references form more details.
    Emacs (or do the Emacs tutorial by pressing control-h t from within Emacs)


    Up to this point, you have been using a program to compile your programs. Now, we will be using the command line to compile your programs. Download both the C and Java hello world programs. We will use these as examples for compilation.

    C Compiling

    The gcc command will be used to to compile C programs. The basic syntax is:

    gcc -o <exe name> <C file>

    The -o option specifies what you wish the executable version of the program to be called. So, for example, the hello.c file:

    gcc -o hello hello.c

    This creates an executable called hello, which can be used to run the program. Do this by typing "./hello" at the command line.

    Java Compiling

    The javac command will be used to compile java programs. The basic syntax is:

    javac <file name>

    So, to compile


    This will create a hello.class file. The program can be executed by typing:

    java hello

    at the command line.

    Note: Compiling a program that consists of multiple files is more complicated than this. We will cover how to do such when necessary.

    C Debugger (GDB)

    C runtime errors are usually not too descriptive. Often, you will just get a Segmentation Fault. This error occurs when a program attempts to access memory that it does not have access to, or is accessing it invalidly. Thankfully, there is a runtime environment that can assist in determining what caused the error.


    First, GCC must be instructed to instrument the code to be run in the debugger. We do this by using the -g flag during compilation. As an example, consider the compiler code that has been provided for use in Exercise 1:

    gcc -o ex1 ex1test.c ex1.c uniform.c -lm

    To be able to use the debugger, we just add the -g flag to the command:

    gcc -g -o ex1 ex1test.c ex1.c uniform.c -lm

    To use GDB, just execute the following command:

    gdb <exe>

    Where <exe> is your executable. This will bring up the GDB command prompt. typing run will execute your code. When it encounters an error, it will display the function call stack (and usually a line number) for you to investigate further. Type q to exit the debugger. GDB is more powerful than this, however. For more information about GDB, go to the GDB Reference for more information.


    1. What is the full command you would use to change from any directory to the CS143 directory in your home directory?
    2. Give at least two separate ways to change into MY (cssmith) home directory? Does it allow you to change to my directory? If so, can you see the files in my home directory?
    3. Are there any hidden files in your home directory? If so, what are they?
    4. What are the permissions on your home directory?
    5. Try to fix hello_bad.c and, and save them in your lab0 directory


    In your home directory create two directories (see the above link to view commands), a cs143 directory, and a submit directory. We need to alter the permissions of your submit directory so that we will be able to access your files. We will use the chmod command.

    chmod a+rx submit

    This gives everyone read and execute privileges to your submit directory. permissions for the submit directory should be drwxr-xr-x.


    All programming assignments will be turned in using Dr. Simha's Submission Script. Please email me your 8 character alpha-numeric encryption key as soon as possible. Be mindful of the Naming Conventions listed at the bottom of the linked page. If your files are not listed correctly in your submit directory, I will be unable to grade your work. Also, make sure that you are using the correct directories as listed in the Submission Script tutorial. Failure to do so will result in a loss of points on the assignment. To complete this tutorial, you will submit the text file of your answers to this lab. I will check these this weekend, and send an email to those who have successfully submitted. submit your work as
    <your name>0
    For example, I would submit as cssmith0.

    Creating A Personal Submission Script

    In order to ease the pressure on you, I have devised a way for you to quickly and easily submit your programs, utilizing Dr. Simha's submit script. In your home directory, open a new document called SUBMIT. On the first line of the file, type #!/bin/bash. This will allow us to use bash scripting to create an easy submit script. Next, place the following lines of code below the previous line.

    jar cvf $1.jar $1
    java -jar ~simha/submit/submit.jar -e <YOUR ENCRYPTION KEY HERE> $1.jar $1.jar.crypt
    cp $1.jar.crypt ~/submit/$1.jar.crypt
    chmod a+r ~/submit/$1.jar.crypt

    Save this file, and then give eXecute privileges to only yourself (U, Ask me if you need help). Now, once your have finished programming your assignment, you can simply call the submit script to submit. For example, if I were to submit our lab0 example, I would do the following:

    cd ~/cs143
    ~/SUBMIT cssmith0

    Make sure that you receive a time stamp during your submission process, otherwise something has gone wrong.