Lab 1: Lab introduction

The goal of this lab session is to help you become familiar with the environment and operating system in the cs lab.

I. The Desktop

A. The name game

Already you've noticed that the computers here in the lab are using an operating system other than Microsoft Windows or MacOS, and with which many of you may be unfamiliar with. You'll also hear a variety of names thrown around: Ubuntu, Unix, Linux, RedHat, NetBSD, and Gnome. Which one of these are the lab's computers running?

The shortest answer is that the name of the operating system we're using is Ubuntu. However, Ubuntu is a variety of Linux, which in turn is often considered a variety of Unix, so you could get away also with saying that our lab uses Linux or that our lab uses Unix. (Technically, Ubuntu is an operating system that uses the Linux kernel, the Linux kernel is a core operating system component which can be used to build a Unix-like operating system, and UNIX is a trademarked name of an old operating system that various companies regularly sue each other over.) RedHat is the name of another variety of Linux, which we used in the lab last year. Our lab does not run RedHat anymore, but you might overhear people talking about it. NetBSD is the name of another (non-Linux) variety of Unix, which we used in the lab up until last year; a few machines in the department still run NetBSD, but none of the Armerding 131 machines. Finally, Gnome is the name of the desktop environment (or windowing system) that we use. It's possible to run Gnome on operating systems other than Ubuntu, and it's possible to run environments other than Gnome on Ubuntu.

B. Exploring the desktop

Take a look under the Applications menu. We'll use only a handful of the available programs in this course, but you may want to try some of them on your own time. Even the games have their place-- sometimes when you're stuck on a programming problem and need a five-minute break, a simple game is the right thing. Look also under the Places and System menus. We will look more at some of these later.

Read this entire paragraph before doing what it says. Notice at the bottom right corner of the screen you'll see what looks like a recycle bin (which it is), and just next to that two rectangles, the left one orange and the right one gray. Click on the right rectangle. You'll see that this window has disappeared. Click on the left rectangle to get it back.

The Gnome environment allows you to have several "virtual" workspaces active. This will come in handy if you have more windows open than is convenient to have on the screen at once. To move a window to a different workspace, right-click on the title bar of the window and select "Move to Workspace Right" etc. Later we will see how to configure your account to have more than two workspaces (I've found that I prefer to have nine workspaces).

II. The File System and Terminal

A. Two ways to look at files.

Under the "Places" menu, select "Home Folder." This will bring up a window called the "File Browser" which lets you navigate the the file system; you'll notice that it looks more or less like the "Finder" in Mac OS and "Windows Explorer" in Windows. The folders (or directories, as we'll tend to call them) which you see there are automatically created for every new account. We won't be using any of these very often.

From the top menu bar of the screen, select Applications->Accessories->Terminal. The window this brings up is alternately called the terminal, xterm, shell, or command line. It provides a way to interact directly with the file system and to execute program by typing in commands. It's an old-fashioned way to work, but once you get used to it you'll find it's faster for many of the things we do. In the next few minutes we'll be learning a handful of commands.

First, type ls into the terminal. You will see that it responds by printing the names of the same directories you see in the file browser. This command lists the contents of a directory. We'll use it as our first example of a Unix command.

Unix commands have three parts: the command itself, flags (optional), and arguments (optional). The arguments tell what to execute the command on, and the flags (which usually begin with "-" or "--") modify the behavior of the command. Now type

ls -l

(That's the letter ell, not the digit one.) You'll see the same directories listed again, but now they're formated differently and with a mess of other information. The -l flag indicates that you want to see the details of the items being listed, including whether the item is a directory or plain file, the permissions-level of the item, the owner of the item, and date and time when the item was last modified. Now try

ls -a

The -a flag indicates that you want to see all the files in the current location, even "hidden" files. As you can see by the result, hidden files are files that begin with a period. Mostly these contain information about your account, including customizations you have done. Certain applications maintain hidden files to keep a history. If you type

ls -la

that is, using both flags (the order doesn't matter), you can find out which hidden files are directories and which are plain files. The ones whose information line begins with "d" are the directories.

Take note of two hidden files in particular: . and ... These are special directory entries and will appear in any location; they stand for the current directory and the parent directory, respectively. The single dot isn't very useful, but try typing

ls ..

will show you the directory that contains all user's home directories--- although you should not go poking into those directories themselves. This does show you the first example of an argument to a Unix command. In this case we gave the name of the directory ("..") whose contents we wanted to list. Likewise,

ls Desktop

Will list the contents of the Desktop directory, which is probably empty.

B. Managing directories

In this section we will learn how to modify and navigate the files in your account. If you ever get lost, you can find out where you are with the command pwd, which stands for "path to working directory." Try it now. You will see something like

/homes/cs235a

Which indicates you are in the home directory for the account cs235a, which is in the directory homes, which contains all the home directories. You can create a new directory with the command mkdir, and you can move into a directory with cd, "change directory." For most labs and projects, you will start by making a new directory and cd'ing into it. Do so now for this lab.

mkdir lab1
cd lab1

Notice that the file browser-- if you still have that window up-- reflects the making of the new directory as a new folder icon appears. In the terminal, you can always go back to the previous directory with cd .., that is, change directory to the parent directory. Also, typing cd alone without any arguments will always take you back to the account's home directory.

C. Managing files

In this section, you will learn to use the following commands:

cpcopy a file
catdisplay a file (or concatenate two or more files)
lessdisplay a file
mvmove (or rename) a file
rmremove (delete) a file

Copy the file aeneid from my Public directory. You will frequently do a copy like this at the beginning of a lab or project, since I will provide starter code for most of your assignments.

cp /homes/tvandrun/Public/cs235/aeneid .

cp takes two arguments-- the first is the "source", the file you want to copy, and the second is the "target" or "destination", the place where you want the copy to go. In this case, "." means "here." Now ls will show that the file is now in the directory.

As you can see in the table above, we have two commands for looking at a file. Most of the time when you want to view a text file, you will also be editing it, for which you'll be using a text editing program. Accordingly, cat and less aren't commands you'll use all the time. They are, however, easy commands to practice with. Try

cat aeneid

You'll see that that the contents of the file are dumped to the terminal. For long files, this is generally not very helpful. We'll use cat for other purposes later. To view a file, you're better off using less. Try

less aeneid

This program lets you scroll through a file using the arrow keys. Hit 'q' to quit. (Why are these commands called "cat" and "less"? cat is short for "concatenate," because the command can also be used to chain several files together, when that's useful. less is a tongue-in-cheek name given because the less command is an improvement over an earlier command called more; the name more was given because instead of giving the file all at once, the command lets you indicate when you want more of the file.)

Next, you can make a copy of a file in the same directory but with a new name. Use cp as before, but give the name of the new file (instead of a new location) as the target, for example

cp aeneid aeneid2

The mv command is similar to the cp command. mv can be used either to move a file from a location to another location or to "move" the file within the same location but with a different name--- in which case what you're really doing is renaming the file. Do the following to make a directory, move one of the "aeneid" files into it, and rename the other one.

mkdir foo
mv aeneid foo
mv aeneid2 aeneid3

Use ls to observe the results. Finally, the rm command is used to remove or delete a file. Try the following.

rm aeneid3
rm foo

First, notice that the terminal never asks you if you're sure you want to delete something; moreover, rm deletes files for good--- it doesn't put them in the trash or recycle bin so you can resurrect it if you change your mind. You'll have to get used to thinking before pressing the enter key. Second, notice that removing the directory didn't work. The terminal will not delete an directory unless it is empty or if you use the -r flag.

rm -r foo

C. Recording what you do

For some of your labs and projects, I will ask you to submit an electronic copy of your files for testing; at other times I will ask you to turn in a hard copy. In the latter case, you'll need a means for recording a demonstration that your program works. To do that, you'll use a command called script. Typing "script filename" will cause the terminal to start recording everything that happens in the terminal to file with the name you have given. To stop recording, type exit. Use script now to make a record of the following:

To print a file, you can use either the command lpr, for "normal" printing, or the a2ps command, which prints 2 virtual pages per physical page. a2ps also does some fancy formatting of some file types; you will probably prefer a2ps. For either command, give the name of the file as an argument. Print your typescript file out now and turn it in at the end of lab.

III. Xemacs

Most of our programming will be done using a text-editing program called Xemacs. Move into a directory that has a copy of the aeneid file or copy the original to your current directory. Then open the file in Xemacs with the following command (with "aeneid" replaced with whatever the name of the copy of the file is)

xemacs aeneid &

Xemacs launches in its own window. The ampersand indicates that you want the terminal to remain active while xemacs is running. If you leave off the ampersand, xemacs will still work, but the terminal window will be locked until you exit xemacs. (If you leave off the ampersand by mistake, you can always open a new terminal window.)

Xemacs has make short-cut key strokes that some people like to use, but almost anything you want to do can be done easily through the buttons and pull-down menus. Two key strokes that you'll want to remember, though, are ctrl-s for searching and esc..g (press Esc followed by G, don't hold Esc) for going to a a line number. In either case, you will be prompted in the very bottom of the Xemacs window (the area of the window called then "mini-buffer"). Try these out. When you are done, you may close Xemacs.

IV. Configuring the Desktop

Spend the remaining time exploring how to customize the appearance of the desktop. Rather than give you directions, I will let you figure this out on your own. Under System->Preferences, you will find items to let you change the appearance, mouse operation, screensaver, etc. If you need help, ask.

Some things in particular you should do:

The changes you make will affect the account you are using. As you make modifications, keep in mind that you might not always use the same account in subsequence lab sessions, so please make only changes that other people can live with. (Later you may log in as yourself and make as many customizations to your own account as you like.)

To log out, go to System->Quit, and select log out.

V. Logging in Yourself

Before you leave, each student should log in as himself or herself. Use your Novell password, the same one you use on the rest of campus. Let me know if you have any trouble.


Thomas VanDrunen
Last modified: Tue Sep 2 09:24:02 CDT 2008