CS 111 Spring 2008 Lab 1
Introduction to the CS Lab Environment and Linux


The objectives of this lab:

  1. Familiarize yourself with the CS lab environment
  2. Familiarize yourself with the Linux operating system

You should complete this lab before class on Wednesday, 2 April 2008. (There's nothing to turn in on paper—the purpose of this lab is just to give you practice with some of the tools that you'll need throughout the term. You'll submit your work on this lab to get practice with the homework submission program ("hsp") that you'll use throughout the term, but it's not for a grade.)

Introduction to the CS Lab Environment

You will be using the machines in CMC 306 for your programming assignments throughout the term. These machines run both Windows and Linux. Most or all of you have used Windows already, but most likely you are not familiar with Linux. Today's lab will help you get started with using Linux.

Windows and Linux are examples of operating systems. An operating system is the set of programs that tells the computer what to do when. It handles things like determining which program or process gets to use the computer at any given time, how data is stored in files, and so on.

In CS 111, you will be programming using the Python programming language in the Linux operating system. In particular, at some point you will need to use the following programs:

If you're reading this assignment from a computer in the 306 lab, then you've already logged in to a computer and started up a web browser. If you're reading this from elsewhere, well, go to the lab! Pick an unoccupied computer, log in, and start up Firefox. (If the screen doesn't say "Red Hat" or "Linux" on it, then you'll have to reboot—the computer is currently set to load Windows instead of Linux. To start Firefox, there's an icon on the top of the screen that looks sort of a like a globe; click on it to get started.)

The computer where you're sitting is named after a famous computer scientist, specifically one who has won a Turing Award (essentially the Nobel Prize of computer science). If you're interested, check out the Wikipedia entry for "Turing Award" and read a brief biography of the person for whom your machine is named.

In this lab, we will be covering the basics of the Linux operating system, including nedit and xterm. (Firefox should be fairly natural, and you'll deal with hsp at the end of this lab.) You will learn some basic commands that you will need to use over and over throughout the course of the term.

Introduction to Linux

Take a few minutes to familiarize yourself with the computing environment. You've already found the web browser; feel free to poke around to find other applications: drawing or graphics programs, word processors, email programs, media players, etc. You can also fiddle with the display settings (try right clicking on the desktop ...) if you'd like.

Now we will learn some of the basic Linux commands. You will be using these commands throughout the term. Before we dive in, though, we have to open up a terminal window. A terminal window, or xterm, is where you type in the commands to interact with the computer: create and delete files, compile and run programs, get help, etc. To open a terminal window, do either of the following:

Note: Both Linux and Python are case-sensitive, so pay attention to what you are typing. Upper-case letter and lower-case letters are different.

Directories

Once you have the terminal window up, type pwd and then hit the Enter key. The command pwd stands for "print working directory"; it lists the name of the directory that you are currently in. Linux organizes everything according to directories (some other operating systems call these folders). Some of these directories are created by the system, but directories can also be created by the user. Each user has his or her own "home directory," where all the files created by that user are placed. This is a bit different from Windows, because on Windows a user can put a file anywhere and there is no concept of a "home directory" (although the "My Documents" folder is close). When you type pwd now, it should show that you are in your home directory. Make a mental note of what your home directory's full name is.

Now type ls (as in lower-case "ell ess") and then hit the Enter key. The command ls is short for "list files and directories." It will list all the files and directories that are currently in your home directory. There should be a couple of things there that Linux automatically creates. You can ignore them.

Let's create some directories. It's a good idea to store groups of things in separate directories. Some people organize their home directories to contain directories named "classes", "programs", "data", "docs", and so on. You might want to create separate directories for each lab or homework assignment for this class. Directories can also have subdirectories; so, for instance, a "classes" directory can have subdirectories "fall07", "winter08", "spring08", and each of these subdirectories can have directories for each class during that term.

Note: While in Windows it's perfectly acceptable to use spaces in your filenames and directory names, in Linux you want to avoid doing this. (You can do it, but it's a bit of a headache to deal with.) So, what happens if you want to have a file or directory name that's more than one word long, like "grad school applications"? You can either use an underscore in between the two words ("grad_school_applications"), or use capitalization to delineate the words ("GradSchoolApplications" or "gradSchoolApplications"). Either underscores or capitalization works fine, though the latter will be consistent with the Python programs that we write.

Type mkdir cs111 in the terminal window and press Enter. The command mkdir stands for "make directory." Now if you type the command ls, you should see that directory listed in your home directory. It has been created.

Now let's create a subdirectory. Type cd cs111 and press Enter. The command cd stands for "change directory." Enter the commands ls and pwd and make a mental note of what you see. You are now in the "cs111" directory that you just created. Now use mkdir to create another directory here, to store the files for this lab that you will create. Name the new directory "ps0".

If you ever want to remove a directory, use the command rmdir. For example, to remove the directory "foo", type rmdir foo. Try creating and deleting some directories now.

Shortcuts: At any time, to return to your home directory, you can just type cd, with no directory name afterwards. To go up to the parent directory of whatever directory you're in, type cd ..

Creating and editing files

Go back into the "ps0" directory that you created. We will now create some files to put in this directory. To create files, we will use the program NEdit. NEdit is a text editor that is very similar to Windows Notepad or other programs you may have used; in fact, it has similar menus and, in most cases, identical "shortcut" keys (such as [CTRL]s to save a file). Start NEdit by doing one of the following:

A blank window should appear. Write a short poem (musical lyrics or the result of gentle random pounding on the keyboard is also okay) in this window, and save it in the "ps0" directory as "poem.txt". Then exit out of NEdit.

Did the poem save in the correct spot? To check, list the contents of the "ps0" directory. You should now see "poem.txt" listed. To view the contents of the file, type more poem.txt. The more command is useful for checking the contents of a file without having to open a text editor.

To remove a file, use the command rm. For example, to remove the file "foo.txt", type:

rm foo.txt

Note that rm will permanently remove a file, so use with care! There is no "recycle bin" or "trash can" in Linux.

Try creating and deleting some more files.

Relocating files and directories

Sometimes, we'd like to move and copy files around. For example, maybe you're afraid that you'll accidentally delete your beautiful poem, so you want to create a backup copy. Or, maybe you made a note to yourself to remind you of a meeting later, and you want to move this to your home directory (where you'll see it) rather than keeping it in your "ps0" directory (where you'll most likely miss it). Fortunately, Linux has commands for these too:

Practice moving, copying, creating, and deleting more files now.

Submitting your work

Submit your poem and the other work that you've done here via hsp. (Note: you can submit entire directories using hsp, so you should just submit your entire "ps0" directory.)

Instructions for using hsp are here.

Getting help

The instructor, prefector, and lab assistants are always great sources for assistance. But you can also get help from Linux itself! You can get help on any Linux command or program by using the man command (short for "manual"). If you type man followed by the name of any Linux command or program, you will get a help page for that program or command. Look at the man pages for all of the commands that we've used in today's lab. Is there a man page for Firefox? For NEdit? For man itself?
Note: To exit out of man, type the letter q.

Notes, tips, and tricks

This page lists all of the commands that we've used in today's lab. Feel free to use it as a reference.


Authored originally by Amy Csizmar Dalal. Modified by Dave Musicant and David Liben-Nowell.