Lab 0

January 14, 2008
cssmith@gwu.edu

Objectives:

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. Normally, this program is also available for download from the GWU help desk homepage, so you can work from anywhere with an internet connection. Unfortunately this is not currently the case. 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 hobbes.seas.gwu.edu. 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.


Unix

  • 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 there I am in my home directory, the absolute path to my cs143 directory is /home/student/cssmith/cs143, while the relative path to it is just cs143.

    Setup

    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.

    cd
    chmod a+rx submit

    This gives everyone read and execute privileges to your submit directory. We can check the permissions through the ls -l command. The first column lists the permissions for the listed file. The first character tells you whether or not the listing is for a directory. The next three characters are your personal (u) permissions for the file, the middle three characters are for group (g) permissions, and the final three characters is for others (o) permissions. An r is for read permissions, w for write, and x for execute. Full permissions are represented with rwx. If a permission is not present, a - takes its place.
    permissions for the submit directory should be drwxr-xr-x.


    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. For the other editors, view the below references.
    Emacs
    Vi


    Compiling

    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 hello.java:

    javac hello.java

    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.