CS21 Lab0: UNIX and vim

Due before class on Friday (Sept 7)

This lab assignment should get you used to running update21 and handin21, and give you some practice with Unix and the text editor (vim).

1. Read the class web pages

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

2. Read some useful 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.

3. Learn some UNIX

To begin the assignment, open a Terminal window. You do this by clicking on the black square in the bottom toolbar terminal or by clicking on the XFCE menu button xfcemenu and then choosing "Terminal".

When the Terminal window opens, you will see the shell prompt which will look something like this:
lemon[~]$

In the above prompt, lemon is the name of the machine you are working on, so this may be different for you if you are working on a different machine.

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

$ cd              # change current working directory to your home directory 
$ pwd             # print current working directory
$ mkdir cs21      # create a new subdirectory named cs21
$ ls              # list contents of current directory 
$ chmod 700 cs21  # set permissions on directory cs21 so only you can access
$ ls -l           # check permissions on files in your home directory (drwx------)
$ cd cs21         # change current working directory to cs21
$ pwd             # print current working directory 
If you are interested, here is some information about the Unix directory structure.

4. Learn the editor...vim

In your cs21 directory run the vimtutor command to learn how to edit files in Unix. Concentrate on the lessons listed below. You can skip the rest if you want (don't spend more than 20-30 minutes on this). And don't worry if you don't remember everything in the tutorial. You don't need to know *all* the commands, and you can come back to it later in the semester. It is most important that you can open a file, edit the contents, save, and quit. The rest are just shortcuts (sometimes really useful shortcuts, but still just shortcuts).

  $ vimtutor    # starts the vim tutorial

Concentrate on the following sections of vimtutor:



5. Run update21 and create bio.txt

note: if you added CS21 late, we may not have you in our list of students who can run update21 and handin21. 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 a Unix editor program, run update21 to get the starting directory for lab 0, then cd into that directory:

$ update21          # creates subdirectory 00 in your cs21/labs directory
$ cd                # cd to home directory (in case you are not there already!)
$ cd cs21/labs/00   # cd into the directory for lab 00
$ pwd               # check to see that you are in the correct directory.
                    # if you are, should list /home/your_uname/cs21/labs/00
The lab submission program, handin21, will grab all files from your cs21/labs/00 directory.

Next, edit the file named bio.txt (e.g., vim bio.txt) and answer the questions in that file.

After you are done editing your bio.txt file, save your changes, exit vim (:wq in command mode), and enter the ls command to list out all files. You should see the bio.txt file. You can also run the cat command on the file to list it's contents to the terminal window:

$ ls
bio.txt
$ cat bio.txt
...
... contents of bio.txt file displayed here ...


6. Submit

Once you are satisfied with your bio.txt file, hand it in by typing handin21 at the unix prompt.

Here is some information about how to run handin21.

You may run handin21 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

Don't forget to attend a Using UNIX session. You can attend any one of these sessions (they are identical):



Logging out

When you are done working in the lab, you should log out of the computer you are using. First quit any applications you are running, like firefox or the Terminal. Then click on the logout icon logout and choose "log out".

If you plan to leave the lab for just a few minutes and then come right back to work, you do not need to log out, but it is a good idea to xlock your machine while you are gone. You can xlock by clicking on the xlock icon xlock, or by running the xlock command at the shell prompt. You should not xlock a machine if you plan to be gone for more than about 10 minutes, and you should not xlock main lab machines during times when classes are held in the lab.

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.tx from current working directory into my cs21/lab/00 directory
  $ mv bio.txt ~/cs21/lab/00/bio.txt 

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

  # also, the tilda (~) is a shortcut for my home dir (ex: /home/knerr)