The goal of this lab is to familiarize you with the equipment and software in the CS Lab. By the end of this lab, you should begin to be able to do a number of tasks using the menus-and-mouse interface, and you should also be able to run a number of commands in a Terminal window.
The usual pattern for our labs will be for you work with a partner (or two), working on one computer. When you are doing that, one of you will be the driver, handling the keyboard and mouse, and the other will be the navigator. When you are working like this, it is important that the navigator understand everything that the driver is doing–preferably before the driver does it. You should swap roles occasionally during the lab.
During each lab, you and your partner du jour will usually be using a lab account, which either the professor or lab TA will have logged in for you. You won’t always have the same partner, and you won’t always be on the same in-lab account.
Today, you should link up with a partner, even though you’ll be driving and you are working on your own account. If you work along together, you’ll have someone to ask questions.
Remember that the purpose in doing the lab exercises is to know how to do similar things in the future. I recommend that you take notes during each lab; you will also find it helpful if, over the semester, you keep a sheet of notes on the Unix commands you learn and of editor operations.
The computers in the Computer Science Lab run different software from what you may be most familiar with, which is likely to be some version of Microsoft Windows or Apple’s Mac OS X. What you see may be called any of Unix, Linux, Ubuntu, or even GNOME. Here is what each of those actually means:
So now we know what everything is, right?
There are twenty-five computers in the lab (Science 154), with the imaginative names cslab01 through cslab25. You might want to know their names, because you can use any of them over the campus network.
The machines that you can see are supported by several more that are hiding in a closet. You won’t need to be directly aware of those, but they are set up so that you can use any of the twenty-five lab machines interchangeably. If you work on one computer, you will see all of the same files when you come back later and work on another one.
Complete the following tasks.
Log in on the console. Our lab is separate from the rest of the campus facilities, but we have set it up so that your account name and password are the same as for your standard campus (Novell, portal, Banner, etc.) account.
Explore the desktop. After you log in, you should find yourself looking at a GNOME desktop—and most of it will be blank space. But it has menus at the top, and some buttons and other useful things will show up at the bottom.
First, a bit of terminology for the mouse. When we don’t say, use the left mouse button, which is what you’ll use the most. ‘Click’ means press and release once; ‘press’ means to hold it (and keep holding it while you move). The X window system was designed for a three-button mouse; usually if you have only two buttons, you can simulate the third by pressing on the scroll wheel. Rolling the scroll wheel up or down will scroll what you are pointing at.
Select Firefox in the Applications, Internet menu to launch a web browser. Then type the URL for this class’s main page in the address box:
You probably want to make a bookmark for that, because you’ll be coming back to that page in the future. Navigate down to this lab; an easy way to get there will be to click on “Labs” near the bottom of the page, to bring up a listing of labs and projects. Then click on the link for this lab. What you see should look a bit like what you are reading right now.
Launch a Terminal window, too; you’ll find it under Applications, Accessories. You can move a window around by pressing in its top bar and moving the mouse.
Now look at the bar at the bottom of your screen. You should see a button there for each window that is open (one for Firefox and one for Terminal). Clicking on one of those buttons will do one of three things:
Typing tips In this and future labs, text that is typed into the computer will show up in a typewriter-like font, like this. References to special keys look like Esc, which refers to the ‘escape’ key (at the top left of the keyboard). A special case is the Ctrl key (lower left), which you hold down (like the Shift key): you’ll see ^c (pronounced “control c”) to mean “hold down Ctrl and type c”. (In some programs, you might see control-c spelled as C-c or ctrl-c, too.)
You’ll do a lot of your work by typing commands to your shell (what that means is explained below); in the instructions, those lines will be in typewriter font and begin with a ‘$’; you won’t type that character.
As a final caution, notice that the letter ‘l’ (ell) and the digit ‘1’ (one) can look quite similar. So pay close attention.
Looking at your files In the Places menu, select Home folder. That will launch a file browser, similar to the Mac OS Finder or the MS Windows Explorer. It will be looking at your home folder.
Now bring your Terminal window to the top. You’ll see a line that starts with your username, has a bunch of other stuff, and ends with a ‘$’; that is the prompt from a program called the shell, which treats each line you type as a command to run a program.
For a first command, type
and hit the Enter key. This command lists the contents of the current directory (folder). You should see the names of the same things that you can see in the file browser window.
Most commands have three parts:
We could ask ls for more information with one or more of several options:
Names that start with a period (often pronounced ‘dot’) are normally hidden; the last of these options says to show them, too. Try giving ls various combinations of options; each option should be separated from what comes before it by one or more spaces.
When you use -a, you’ll see that there are some names starting with dot. Two of these names are special:
After the options, you can give ls the name of a directory/file (or more) that it should list; if you don’t supply a name, it will list ‘.’. So try listing the contents of ‘.’, ‘..’, and other directories that you can see. Combine those with options, too, as in
Notice that Unix commands tend to be short and a bit cryptic. It may be a little intimidating, but you should be able to remember the ones you need most often.
Making directories and wandering about You might use these computers for more than one course; so it would be a good idea to make a directory for this class. You do that with the command mkdir:
If you now list the current directory, you should see the one that you have made. Notice that Unix commands typically do not print anything when they work; mkdir will complain if it doesn’t work, but if all you get is your command prompt, the command worked.
You can change the current directory with cd. But before going somewhere else, it is good to know where you are; the command
will print the current working directory. You should see something like /homes.all/linux/msnerd, except with your user name instead of msnerd.
Now change into the directory you’ve made, and print where you are:
If you want to go up to the containing directory, use the special name dot-dot:
It is also good to remember that you can always go home by giving cd without an argument. It is also convenient that they shell will treat a name that starts with ~/ as starting in your home directory, no matter where you are.
You might want to try the same moves in your File Browser: you can move into a folder by double-clicking on it. The upward-pointing arrow will take you into the parent of your current directory.
In your terminal window, change back into the directory you made for this class, and pwd to make sure that you are there. Then make a directory lab1 for today’s work, and cd into it. Print the directory to see where you are.
Warning: Unix commands usually act as if you mean what you said; so they won’t normally ask you if you really meant to do something. It is a good idea to pause and think about it before you hit Enter when a command might do some damage. If you want to be cautious, the rm, mv and cp commands described below can be given a -i option (right after the command name) to make them ask before they overwrite or delete anything.
Now you are going to copy a file to use in this lab; use the command
Notice that there is a dot as the second argument; this command says to copy a particular file from the class directory to dot, the current directory. If you use ls, you should see it now.
If the second argument is a file name, you’d copy the file to that name. So you could try
If you list the directory, you should see both of them.
You rename a file by moving it with mv. So try
That will not work, because there is no file named Funny.java. If you use -i, you can try
it will ask you if you really want to, because the move would cause the old PrimeFact.java to be discarded.
To delete a file, you remove it with rm. Be careful, because what is removed is gone for good. You could try
The * is a wildcard; it matches any filename. If you say yes, you will remove all of your files in this directory—which is O.K., because you can copy PrimeFact.java from the class directory again.
Inside a file If you want to just look at what is in a file, the easy command to use is less. (There is a silly story that explains the name.) So, if you have a copy of PrimeFact.java, you can look at it with
You’ll be able to page through the file; the keys you want to know are that q will quit and space will page forward. If you want to know more, try h for help.
For editing, we recommend that you learn at least a little about working with a program called XEmacs. You’ll usually start it up with the name of a file to work on; you’ll also add an ampersand to the end of the command. So try
You’ll notice that xemacs creates a new window to work in; the ampersand tells the shell to prompt you for a new command as soon as xemacs has started, instead of waiting for xemacs to finish.
XEmacs (like other “Emacs” programs to which it is kin) is a very powerful, customizable editor. If you’re going to do very much work, it will be worth taking some time to learn to do lots of things without taking your hands off the keyboard. But you’ll be able to manage for now using the mouse, the arrow keys, and the buttons and menus at the top of the window.
You should be looking at the contents of PrimeFact.java that we’ll come back to in class. Change the author’s name to yours, the part about it being an in-class example to “Lab 1”, and the date to today’s.2 Tip: xemacs inserts what you type if it is a normal letter. If you want to delete the letter you are on, use ^D. There are lots of things that you can do; keep in mind that xemacs often uses the Ctrl key, and that it sometimes uses ^X or Esc as a prefix (typed before another key or sequence of keys). The key that you want to remember in xemacs is ^G, which is the general-purpose “stop whatever I am doing” key.
When you have made your changes, save the file. (I’ll let you figure out how.) Then go back to your terminal window. If you ls, you’ll see that there is now a file with a tilde on the end of its name: xemacs makes a backup copy of a file when you edit it, which may save you sometime if you manage to make a mess.
Compiling and running a Java program The file PrimeFact.java contains a program in the Java language, which is intended to be at least somewhat intelligible to human beings. (It may not seem so now, but it will soon.) For the computer to run the program, you must first translate it into a form intended for the computer; the cammand that does the translation is called a compiler. To compile your Java program, use
If you ls, you should see a new file named PrimeFact.class, which is the compiled (machine-oriented) version of your program. You can run it with
Now use your editor to change the number to be factored, recompile, and run it again.
Note: The compiler javac works on files; so you specify a full filename for it. The java command works on the program, using whatever class files it finds; so the argument there is the name of the program (which is expected to match the first part of the name of the .java file).
There is nothing to hand in this week.
If you have time (it takes about thirty minutes), you might want to walk through the tutorial built into XEmacs. You can start it by typing Esc ? t. Or you might want to come back to the before the next lab meeting to do it. Whether you do the tutorial or not, it would be a good idea for you to keep a sheet of notes as you learn to use the editor.
Before you go, please exit XEmacs and log out.
1Or, if you think like a lawyer, the trademark is UNIX (in all capitals). It was originally owned by the Bell Telephone System, back when that was the U.S. telephone monopoly. One of the reasons that UNIX became popular in universities was that Bell could not go into the computer business because of their telephone monopoly; so they close to gave away UNIX to universities for a number of years.
2Actually, it would be bad form to change the author’s name to yours, because that would be claiming someone else’s work as your own. But we’ll do it today as an exercise in editing.