CS21B Lab0: Using Unix and Editing Files

Due: Complete before class on Thursday

This lab assignment should get you used to running update21b and handin21b and give you some practice with Unix and editing files.

1. Read the class web pages

Start by reading through all of the CS21B homepage. Pay special attention to the Schedule, Academic Integrity and How to succeed in this class parts. You should get into the habit of checking this page weekly; the class schedule, quizzes, lab assignments, weekly readings, and announcements will be posted to the class Schedule weekly.

2. Read the CS web pages

Go to the CS homepage (http://www.cs.swarthmore.edu/). From there click on the "cs lab help" button and read the Welcome Message, The User Agreement, and The CS Lab Rules pages.

To begin the assignment, open a Terminal window. You do this by clicking on the black square terminal in the toolbar at the bottom of the screen.

If you are in the Mac Lab (SCI 256) and there is no terminal icon in the toolbar, click on the magnifying glass in the upper-right corner of the screen and type in terminal. Click on the terminal icon that appears as a result of the search.


Connecting to the Computer Science network

If you are in the Mac Lab (SCI 256) you'll need to do one additional step to log on to the CS machines. If you are in one of the CS Labs (SCI 238 or SCI 240) you can skip this step.

Inside the terminal window type the following, but replace username with your own username.

ssh -X username@lab.cs.swarthmore.edu

The terminal window should have a prompt which will look something like this:
lemon[~]$

Each machine in the CS domain has a cooking ingredient name. In this example it is lemon, but when you do this command you will most likely be on a different CS machine.


3. Learn some Unix

If you don't have one already, create a cs21b subdirectory in your home directory. Here is an example of the commands to enter to do this and to verify that it worked ('$' is the prompt and text after '#' are comments explaining the commands):

  $  cd               # change current working directory to your home directory 
  $  pwd              # print current working directory
  $  mkdir cs21b      # create a new subdirectory named cs21b
  $  ls               # list contents of current working directory (your home directory)
  $  cd cs21b         # change current working directory to cs21b
  $  pwd              # print current working directory 
Here is some information about the Unix directory structure.

4. Learn the editor emacs

In the terminal window start the editor as follows:

 $ emacs

A new editing window will open. Click on the Help menu and select Emacs Tutorial. Start reading from the top. You can stop when you get to the section on buffers. This tutorial will take about 20-30 minutes to complete.

I have created a short Emacs Summary to help you remember the most frequently used commands. You may want to print this and bring it with you to class the first couple of weeks.


5. Run update21b and edit bio.txt

Note: if you added CS21b late, we may not have you in our list of students who can run update21b and handin21b. Send me email if you have problems and I'll add you to our list so that these will work for you.

Once you have learned how to use emacs, run update21b to get the starting directory for the initial lab, then change into that directory:

$ update21b           # creates subdirectory 00 in your cs21b/labs directory
$ cd                  # cd into your home directory
$ cd cs21b/labs/00    # cd into the directory for lab 00
$ ls                  # list the files in this directory, should contain bio.txt

For this lab, the program handin21b will only submit files in this labs/00 directory.

Next, start up the editor and open the file bio.txt:

$ emacs bio.txt

Before you begin answering the questions, you can set up emacs so that it will automatically fill each line with the appropriate number of words. Press Esc-x, type auto-fill-mode, and then press Enter. You should see at the bottom center of the emacs window the word Fill appears.

After you are done editing your bio.txt file, save your changes and exit from emacs. Run the cat command on the file to catalog it's contents to the terminal window:

 $ cat bio.txt

6. Submit

Once you are satisfied with your bio.txt file, hand it in by typing handin21b at the unix prompt. You may run handin21b as many times as you like, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them.

Using Unix Sessions

Don't forget to attend a Using UNIX session. You can attend either one of these sessions (they are identical):
  Tuesday, Jan. 18, 4-5pm, SCI 240
  Wednesday, Jan. 19, 8-9pm, SCI 240


Troubleshooting

If you can't find a file you created, check to see that you are in the directory you think you are.

If a file isn't in the directory you want it in, use the mv command to move it from its current location to a new location in your directory structure. The general form of the mv command is mv source destination, where source is the pathname of the file you want to move and destination is the pathname of the file you want to move it to. For example:
  # moves bio.txt from current directory into your cs21b/lab/00 directory
  $ mv bio.txt ~/cs21b/lab/00/bio.txt

  # this does the same thing, '.' means a file with the same name as the source
  $ mv bio.txt ~/cs21b/lab/00/.