CS21 Lab 0: Linux and vim

Due by 11:59pm Thursday, 3 September 2009

This lab assignment should get you used to running update21 and handin21, and teach you a few of the common commands used in the Linux/UNIX terminal window.

Read the class web page

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, homework assignments, weekly readings, and announcements will be posted to the class Schedule weekly.

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 user agreement form, and lab rules pages.

Using Linux

Much of this assignment will introduce you to some common Linux commands. We will review these commands regularly in class, and you are also encouraged to attend one of the using Linux help sessions this week in Science Center 240. You may attend either session.

Learn some Linux

To begin the assignment, open a Terminal window. You do this by clicking on the black square in the center of the 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 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     # make cs21 dir only accessible to you
  $  ls -l              # list permissions (cs21 should be drwx------)
  $  cd cs21            # change to cs21 directory
  $  pwd                # print current working directory 
Further information about the Unix directory structure can be found on the department's web site.

Learn the editor...vim

In your cs21 directory run the vim tutorial to learn how to edit files in Unix. Concentrate on Lessons 1, 2.6, 2.7, 3.2, 3.2, 4.1, 4.2, 6.2, 6.3, and 6.4. 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           # start the vim tutorial
There's also a nice vim refernce card.
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 into your home directory
$ 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, pwd should list: 
		       # /home/your_user_name/cs21/labs/00
The program handin21 will only submit files in this labs/00 directory.

Next, start up vim (or gvim) and open a new file named bio.txt and answer these questions:

  1. Tell me about some of your strengths. What are some things that you are good at doing (they don't have to have anything to do with CS)?
  2. Tell me a bit about why are you taking CS21.
  3. Tell me about any prior CS experience you have.

To start editing the file:

$ vim bio.txt

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

$ cat bio.txt

Submit

Once you are satisfied with your bio.txt file, hand it in by typing handin21 at the unix prompt. 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.

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 /home/knerr/cs21/lab/00/bio.txt

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