CS 120: Computer Science I

Laboratory 01
X Windows, Unix, and Korn shell

Overview

The purpose of this lab is to introduce you to the Computer Science laboratory. This lab will not be graded; the main objective is to help you become familiar with the system so that you can work productively the rest of the semester. Please take your time, pay attention to what is happening, and feel free to experiment and ask questions. You may want to take notes on things that are unfamiliar or which you will find hard to remember. You also might want to come back to the lab in a few days and spend some more time getting comfortable with the system.

Accessing the Computer Science Laboratory

The Computer Science lab is attached to the west side of the Collier Hall of Science, next to the parking lot; the outside building door next to the CS lab is always unlocked. Everyone with permission to use the lab should know the combination; do not prop open the door, or give out the combination. No food or drink is allowed in the CS lab.

Sit down at any of the computers in the lab; if the screen is dark, hit any key on the keyboard, and the screen should light up. Never attempt to reboot, turn on, or turn off any of the equipment in the CS lab; unlike Macs and PCs, they should be left running all of the time. If you have problems with the computers themselves, see Myron Kowalski (the MoCoSIN network administrator) or one of the CS faculty. Myron's office is 212 Collier, and his email address is myron@cs.moravian.edu. His job is to keep the network and computers running, not to help you design or debug programs...

All of the CS machines use the Unix operating system. Unix was developed in 1974 by Dennis Ritchie and Ken Thompson at Bell Laboratories. (Ritchie also designed and implemented the first version of the C programming language.) One of the main goals of Unix (and C) is to provide a powerful, flexible, computing environment for people who spend a great deal of time using computers.

Unix was designed to support many users with a reasonable level of security; in order for the system to know who you are (and thus what files and programs you can use), you must login by providing a username and password. The CS machines also use a windowing system called X Windows (developed at MIT), but some use a version called OpenWindows, and others use CDE, the Common Desktop Environment. Fortunately, there isn't much difference for our purposes. The newer computers have a graphical login screen, while some of the older computers have a uglier text-based login prompt. In the graphical login, you may have to use the mouse to move the pointer, and click with the left mouse button. (The left button is usually used to select icons, buttons, etc.) Both will prompt you for your password after you enter your username. Unix is case sensitive, so the difference between upper and lower cases letters is important. If you have an account on the CIT computers, you will have a different username and password in the CS lab.

Sharing or copying account information is a violation of the campus acceptable use policy, and will be treated as such.

Once you enter a valid username and password, a variety of windows and icons will appear on the screen. Don't worry if they don't all make sense right away. If you are asked to choose between "CDE" and "OpenWindows", choose "CDE". One of the windows may be a tutorial or introduction to the windowing system. If you don't see such a window, find the icon in the toolbar at the bottom of the screen that has books and a question mark. Click on the arrow above the icon, and you will see a menu of choices. Click on "Desktop Introduction". If your screen doesn't have a toolbar, move your mouse away from any window, click on the right mouse button, and look for a menu entry titled "Tutorial" or "Introduction".

However you get to the tutorial, follow it until you feel comfortable, and refer back to it in the future when you want to find out how to do something new. (If you have used other computers with graphical interfaces before, you may be able to go through this pretty quickly.)

Netscape and the World-Wide Web

Since the rest of the instructions for this lab are on the World-Wide Web, the next thing you need to do is start Netscape, a web browser. Netscape may start automatically when you login; if not, move the mouse away from any windows or icons, hold down the right mouse button, and look for a menu containing Netscape. (The right button is usually used to access menus.)

Once the Netscape window appears, you should see the MoCoSIN homepage. If not, select Open and type http://www.cs.moravian.edu. Part way down the MoCoSIN page is a list of the science departments and faculty. Click on Tom Linton to go to my homepage; near the top of my page are the courses I am teaching. Click on CS 120 to go to the course homepage. Near the top of the page, click on Lab 01 to get to another familiar page (the handout you are currently reading), and scroll down until you reach this point in the text. From here on, you can use the electronic version.


If you have never used a web browser before, you should go through the Netscape Handbook, which can be accessed from the Netscape Help menu. You can save bookmarks in Netscape which point to web sites you'd like to go back to; for example, you should probably make a bookmark for the CS 120 homepage. Here are some other interesting sites to explore:

If you've never used the World-Wide Web, spend some time exploring in the next week or so; there is an amazing variety of information online.

CS Lab Computers and Printers

If you haven't already, take a moment to look at the different models of workstations in the CS lab. The SLCs and ELCs (also called "diskless machines") are the oldest machines; everything except the keyboard is built into the black and white monitor. They still work for some purposes; please tell Myron if you have problems with them. The IPCs and Classics (sometimes called "lunch boxes") are somewhat newer; they all have color monitors. The Sparc 4s and Sparc 5s (sometimes called "pizza boxes") are even newer, and the Ultras are the newest machines currently in the lab. Each computer has a name; if you have problems, be sure to tell us which machine you were using. All of the computers are on a network with some very fast servers which have software and user files, so you can access your own files from any machine in the lab.

There are two printers in the CS lab, and a few others scattered around the building. Each printer is labeled with its name; there are several different ways to print files, depending on the software you are using. By default, anything you print should go to a printer in the CS lab. Please get help if one of the printers doesn't work; we can't fix problems unless we know they exist.

Other Useful Programs

Look at the various menus and submenus of applications and tools (which appears when the mouse is over the background and you press the menu button). There are a variety of programs you may find useful. If you went through the tutorial, you've already used the File Manager and Text Editor. For example, there are clocks, calendars, calculators, word processors, and drawing programs.

You should use folders (also known as directories) to keep track of your files; for instance, you could have a folder for this course, and separate folders within it for each homework assignment. It can be hard to keep track of everything if all of your files are in a single directory.

The Korn Shell

There is a common tradeoff in computer science; often there is a difference between programs that are easy for occasional users to learn and use, and programs that are flexible and powerful for frequent users. GUIs (Graphical User Interfaces) are useful for some purposes, but for other purposes it may be faster and more effective to use a command-line interface. This requires a bit more expertise, but often makes it possible to do things you couldn't do with a GUI.

In Unix, command-line interfaces are called shells, and there are a number of different shells you can use. At Moravian, the korn shell (named for David Korn) is the default, but you can use others if you prefer. To start a shell window (also called a terminal window, since it is similar to old fashioned terminals), hold down the menu button (on the right of the mouse), and select Terminal from one of the submenus. You should get a window with a scroll-bar, and a prompt of some sort - it will probably contain your name or the name of your machine. You can type commands at this prompt, and the results will (usually) be displayed in the same window. Note that you can open several different shell windows so that you can work on several different projects at once (large monitors are very useful for this purpose!)

The more frequently a Unix command is used, the shorter its name; it may take a while to remember the commands, but you can type them very quickly. Many of the commands you will be learning in this lab are only two or three characters long; you will probably type them hundreds of times this semester!

Reference Manual

The first, and perhaps most useful, Unix command you should know is man, which is used to find and display pages from the online reference manual. Type man, and hit return; you should see a short usage message like this:

usage: man [-] [-adFlrt] [-M path] [-T macro-package ] [ -s section ] name ... man [-M path] -k keyword ... man [-M path] -f file ...

Many (but not all) unix commands have such usage messages; the goal is to remind you how the command works, not to give you an exhaustive description. (Remember, most users already know what the command does, and simply want a reminder of the syntactic details.) Thus you probably won't learn how to use man from the message. Instead, type man man and hit return; we'd like to see the manual page for the man command itself! Read through the man page for man briefly, but don't worry if you don't understand the details; most of them won't concern us in this course. At the bottom of the screen you'll see a line like this:

This indicates that you have seen about 6% of the man page; hit the space key to see the next screenful of information, or type q to quit this man page and return to the shell prompt.

All of the man pages have a similar format; they begin with a synopsis of how the command is used, followed by a more detailed description, and possibly a list of related files, error messages, etc. Remember that you can always open another shell window if you want to refer to a man page while you're running other commands or editing a file. (There are also graphical interfaces to the man pages if you prefer.)

Most Unix commands accept a series of optional arguments, possibly followed by one or more required arguments; the usage message puts square brackets around optional arguments. Optional arguments are often used to modify the default behavior of the program, so if you want a command to behave in a slightly different way, it's a good idea to check the man page for an appropriate option. The cd (change directory) and ls (list directory contents) commands (described below) will demonstrate this, and you can read their man pages to learn more about them.

Changing Your Password

One thing you should do now, and at least once a semester in the future, is to change your password. The password you were assigned probably isn't very easy to remember, so choose another password that is easy for you to remember but not easy for someone else to guess. A mixture of numbers, punctuation, and upper and lower case letters is harder to guess than a name, word, or number.

Type passwd to change your password; the program will ask you to type your old password once (to prevent someone else from changing your password), and then ask you to type your new password twice (to make sure you haven't made a mistake in your new password). If you can't change your password, send email to me or Myron and include the exact error message (you should be able to copy and paste it from the shell window into your email message).

As of Solaris 2.6, your password must meet the following requirements:

Manipulating Directories

Files are stored in a tree-like structure of directories (also called folders). All of your files are stored in your home directory, and by default the shell programs start running in your home directory. Type pwd (which stands for print working directory) to see what the current directory is.

You should see something like /users/clif, which means that /, the root directory, contains a directory named /users, which contains a directory with your user name. Type mkdir temp to make a new sub-directory called temp.

You can use the File Manager to create directories, and do most of the other things described in this lab, but you should learn the shell commands too, since there are times when you'll need to use them instead. Tpe cd temp to change the current directory to the new sub-directory (cd stands for change directory). Type pwd again to see the new working directory. There are several ways to get back to your home directory; you can type cd .. to go from any sub-directory to the enclosing directory, or you can type cd ~ to go directly to your home directory from anywhere else in the system.

Use rmdir to remove unwanted directories, but please don't remove the temp directory yet, and be careful about removing directories if you don't know what's in them. (Feel free to ask about specific files or directories.) Unlike most Macs and PCs, Unix prevents users from deleting directories or files that were created by other users, but you can create serious problems for yourself by removing directories or files in your home directory which are needed by other programs.

Manipulating Files

Go to your home directory, and use the ls command to print a list of files and directories in a particular directory. (Depending on which tutorials you completed, and what else you've been doing with your account, there may be a variety of files in your home directory.) The ls command accepts an argument to specify that you want to list the files in another directory; type ls temp to see the contents of temp, for example. ls also accepts options to specify what sorts of information to display about each file, so that you can see how big the file is, when it was created, who can access it, etc; check the man page if you're curious...

Usually you will use a text editor to create files containing programs for homework assignments. You may use any of the text editors on the system, but the one called nedit is easy to use and includes some special features to help programmers, and can be started from the command line by typing nedit. Start a text editor, type something simple, like a favorite verse or quotation, and then save the contents as a file called test1 in your home directory. (Hopefully you are starting to feel comfortable enough to do this without explicit instructions; if you can't figure out what to do, ask for help.) Once you've saved the file you can close the text editor and return to the shell window.

If you type ls now, you should see the file you just created. Use the mv command too move a file (or to change it's name); thus you would type mv test1 test2 to rename your file test2. Similarly, use the cp command to copy test2 to test3. Finally, type rm test2 to remove test2.

There should still be a file named test3 in your home directory, plus whatever other files you've created there in the past.

Submitting Assignments

For the rest of this course you will use the grade program to turn in your homework assignments. Create and edit a file named lab1 which contains any questions on this lab, and any comments or suggestions you have for the course so far. I need your feedback to make this course more effective in the future. If there are other things you'd like to learn how to do on the Suns, please let me know what they are. Type grade (without any arguments) to see a helpful message, and see if you can turn in the file you have just created.

Summary of Commands

In this lab you've been introduced to the following commands; remember that you can read the manual pages to learn more about them:

Email

To read and send electronic mail (email) you can use Netscape (which has a separate mail window), or the Mail Tool. In either case, your MoCoSIN email address is simply your user name followed by @cs.moravian.edu. Thus, my email address is linton@cs.moravian.edu. This email account is different from your CIT account, if you have one, but it is possible to automatically forward mail from one account to another account. Once you've learned how to edit text files, Myron or I can tell you how to forward mail from your Unix account; contact the CIT if you want to forward mail from your CIT account.

To let me know that you've finished this lab, please send me an email message and answer the following questions:

General Advice

Computers and programs are always changing; old programs are ``improved'', and new programs are developed which adapt the best features of previous programs. Thus, another aspect of ``problem-solving'' in computer science is figuring out how to use unfamiliar programs or features. If you ask someone else for help the instant you encounter a problem, you'll never learn how to solve such problems on your own. (In most cases, a computer ``expert'' is simply someone who has encountered your problem many times.) At the same time, I don't want you to waste time or become frustrated in this course. Therefore, please make an honest effort to solve problems on your own before seeking help. When you ask for help, describe how you tried to solve the problem on your own; the more information you provide, the more help you will get. If you haven't bothered to read the documentation, you may not get much sympathy when you ask for assistance.

I'm confident that everyone is capable of doing well in this class, but it may take some time and effort to develop the necessary skills. By the end of the term, most of the material in these first few labs will be second nature to you.

Summary

So far, so good! Depending on your prior experience, and how much time you spent in the tutorials, you should have a basic idea of how to get around on the Suns. Depending on which windowing system you're using, there should be a Logout or Exit command on a menu somewhere, or an EXIT sign on the toolbar; it's a good idea to wait until you see a new login prompt to be sure you're no longer logged in. Please continue to work with the tools you've seen so far. In the next scheduled lab, when you will learn how to write, debug, and run a simple program!


This page maintained by Tom Linton, linton@cs.moravian.edu