CS 3, Section 1
MiniLecture - Apr 9, 2001

Hello and welcome to today’s CS 3 minilecture. Whether you are officially assigned to this section or otherwise, you are free to attend whichever sections fit your schedule. We hope you find this section informative enough to continue attending.

Personal information

Section 1b : Stephen Bird | bird@ugcs.caltech.edu | Lloyd 223 | x1694

Introduction to Unix

You will need to familiarize yourself with the Unix environment, because that is what all the UGCS computers use. To this end, we have listed a few important commands for navigating Unix. For MS-DOS users, corresponding command is included.

Task Unix MS-DOS
Display the contents of a directory ls dir
Move to a different directory cd cd
Copy file(s) to a new name or a directory cp [file(s)] [directory or file] copy [file(s)] [directory or file]
Move file(s) to a directory mv [file(s)] [directory] move [file(s)] [directory]
Delete file(s) rm [file(s)] del [file(s)]
Rename file mv [old file] [new file] rename [old file] [new file]
Make a new directory mkdir [directory] mkdir [directory]
Remove a directory rmdir [directory] rmdir [directory]

The Unix file system also seems a little tricky at first. Your base directory consists of the directory /home/USERNAME where USERNAME is the name of your UGCS account. From here, you can create whatever directories you want. Say you created a directory for your first lab’s code. Then you wanted to copy the lab 1 code stored in Lab1.java into that directory and return to your home directory. The commands would look something like:

  mkdir lab1 -- make the new directory
cp Lab1.java lab1 -- copy the file to the new directory
cd lab1 -- move to the new directory
ls -- check that the file was copied
cd .. -- move down one directory
pwd -- check which directory you are currently in
cd lab1 -- move to the new directory again
ls -- check again for luck that the file was copied
cd ~ -- move to your home directory

Whenever you start an application from the command line in unix, you will be unable to type anything on that command line until you quit the application you just started. For example, if you type emacs at the command prompt, you will have to quit emacs before you can type anything else on the command line. To get around this, add an ampersand "&" after the command, ie. emacs&. This starts the application in background mode. If by accident you already started an application without the &, press Ctrl-z (which suspends the application and returns you to the command line), and type bg in the command line. This places the application into the background and returns you to the command line.

Introduction to emacs

Although you can accomplish all your programming in Netscape, it has been known to hang occasionally. With autosave and recovery features, editors such as emacs and vi are a far better choice. After editing your code, you can then copy and paste the code into Netscape for testing and compiling. Since emacs takes less time to become comfortable with, we have listed a few important commands. Please note that preceding a key with Ctrl- in this chart means pressing the key while holding down the Ctrl or Control key.

Task Command
Begin emacs Type emacs at the command prompt
Open a file Ctrl-x Ctrl-f
Save a file Ctrl-x Ctrl-s
Search the file for a word or expression Ctrl-s
Quit emacs Ctrl-x Ctrl-c

Of course, if you are using the graphical version of emacs, you can do all of that from the menu, which is easier, but slower. Two things with emacs you should watch out for:

Running your Java code (finally)

After successfully editing your lab1 program and saving it in your lab1 directory, you’ll need to compile and test it.

Suggestions to help introduce yourself to Java