Assignment 1

Part 1: Intro to CSlab

The CSlab includes 25 computers, each of which can be running either NetBSD (a version of Unix) or Microsoft's Windows XP. For this course, we'll be using Unix.

There are twenty-five CSlab systems, named cslab01 through cslab25, and they are all pretty much interchangeable. If you work on one of them, log out, and come back to work on another one, you'll see all your files, just as if you were on the same machine. There is another machine, named cslab, in the back room, where your files are actually stored. While it's possible for you to work on cslab, you'll normally work on one of the 25 machines out front.

1. Log in on the console.


Our lab is separate from the rest of the campus facilities; so, you have distinct account in CSlab. Your account name is the same as your e-mail/ACNET account, but your password is maintained separately.

Unix pre-dates most software you've used before; so, some things may not operate in the way to which you are accustomed. You should generally assume, for example, that case (capitalization) matters. To log in you'll need to type your username, then hit ``Enter'' to move to the password prompt. Nothing will echo when you are typing your password, which (if you haven't changed it) will be your 5-digit student ID number, your first (preferred) and last initials, and the last four digits of your SSN. (If you've used CSlab before, your password should be whatever you last set it to.)

If you log in successfully, you'll get a display of your desktop.

2. Explore the desktop

The display system in CSlab is known as the X window system. You can use the mouse to do several things, of which we'll describe only a few.

First, a bit of terminology. When we don't say otherwise, 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).

There is a window at the lower left of your screen, and it includes a 4x4 grid. Your desktop is actually 16 times the size of the screen; if you move the mouse off the bottom or right edge, the display will jump to show you another section. The grid is a tiny picture of your entire desktop, and you can move to a particular portion by clicking in one of the cells.

Pressing the left button while pointing at background will pop up a menu of commands you can run. When you have logged on at the console, you have to (eventually) log off by selecting `Exit Fvwm' (at the very bottom) and then `Yes, Really Quit'. But you have other things to do before you log out.

Pressing the right button while pointing to the background will pop up a list of windows that are currently exist somewhere on the desktop. Selecting one will take you to it.

Pressing the middle button (which is the same as the scroll wheel) will give you a menu of commands that can be applied to a window.

3. Start an xterm

The main program that you will launch from that menu is xterm. (You can launch others, but you'll actually start most programs from the command line.) Launch an xterm by pressing the left button and selecting `Xterm'. A new window should appear, with the title `xterm' (so that you now have two xterm windows).

Xterm is a program that emulates (impersonates) a simpler terminal in a window on your screen. You can drag the window around it you press (and hold) the left mouse button in the middle of its top bar or the middle of its other three edges. Grab it near the corners, and you can stretch or squish it to a new size. The buttons at the top bar either pop up a menu or cause other actions. (If you turn the window into an icon---called minimizing it---you can restore it by double clicking the icon or by single clicking on its name in the icon box (which should be at the lower right of your screen). You can also pull any window to the front by selecting it from the pop-up menu you get when you press the right button while pointing at the background (desktop).

4. Run some commands

When you started the xterm, it connected the terminal to a program called a command interpreter or, on Unix systems, a shell. The shell displayed a prompt; it is waiting for you to type a command.

Unix commands typically have three parts: the command proper (or the name), a set of options (called flags), and a set of arguments. For many commands, the options and arguments are optional.

Many of the most commonly used commands have cryptic two-letter names. You may (or may not) eventually come to appreciate the terseness. For example, the command to list your files is ls. Type that command now, with nothing else on the line. If you've never done anything with your account, you may not see anything, or you may see a list of a few names. Unix commands tend to be terse in what they print, too: they usually print explanatory messages only when they don't work.

Type the command again, but add the option for `all' to it, so that the command is now
ls -a
(The space between the command and the option is important.) You should see at least two entries, for `.' and '..' (which we'll explain later). By convention, Unix commands have options that begin with a dash, like the `-a' above. (In keeping with the terseness, many options are single letters.)

Finally, the typical Unix command also takes arguments---usually the names of files or directories (directories are the same things as folders). If you wanted to list the files in a particular directory, you would add its name as another word (separated by a space) at the end of the command, as in
ls /scilab

5. Use ssh to log in to cslab

One feature of Unix is that you do not have to be sitting at a machine in order to interact with it through a shell. Instead, you can use a shell on one computer to interact with another computer. The preferred program for doing is the Secure Shell, for which the command is ssh. Connect to the machine named `cslab':
ssh cslab
Ssh is called "secure" because it has many (fairly paranoid) security restrictions. You may get some warning messages when you connect to a machine for the first time.

You will next be asked to provide your password, which is the same on cslab as on the other machines in the lab. Type it (nothing will display) and hit `enter'. Once you get logged in again, you'll see a prompt---but this time it is for commands that will run on cslab instead of the machine where you are sitting. (If, for some reason, you can't remember what machine a shell is running on, the command hostname will give you its name.)

You can end your shell on cslab by logging out with the command logout or exit, but don't do it yet. You'll need to be on cslab for the next step, in which you change your password for all of the CSlab machines.

6. Change your password

To change your password, you need to be on cslab, not one of the other machines. The set of passwords is periodically copied from cslab to all of the other machines; so a change made on cslab will (after a few minutes) take effect throughout the lab. A change made on any of the other machines will (after a few minutes) be wiped out by the original password from cslab.

The command to change your password is
passwd -l
That's a letter (ell) in the option, for `local', not a one. The passwd command will prompt you for your old password, and then have you type your new password twice. (Remember that nothing will echo, and you'll need to hit `enter' after each password.)

After you've successfully changed your password, you should log out from cslab, so that you do the rest of this on the machine where you are sitting. Unless you've made changes to your account, you'll see the name of the machine where you are working in the command prompt.

Part 2: Learning to use XEmacs


The text editor you will use to write programs is XEmacs. Start it with the command
xemacs &
The & on the end of the command tells the shell to run the program in the background, meaning that the shell immediately gives you a new prompt. This is a convenient way to run programs that work in their own windows, as XEmacs does when you are on an X display.

XEmacs has a huge set of keystroke commands which people who master can use to work very rapidly. Realistically, though, the menu and button interface makes learning the keystrokes unnecessary. Open a new file by clicking on the "Open" button. A mini-window will come up showing the files in the current directory (more on that later). You can either enter the name of the file there or middle-click on the one you want. Enter the name of a file that doesn't already exist to create a new one.

Enter some text and then save it. Exit XEmacs. Then start XEmacs again, this time giving the file you created as an argument.
xemacs (the file you just created) &
If you want to make a quick change to a file, you may also be interested in using a simpler text editor called pico. It is text-based, so it operating inside the xterm.
pico (the file you just created)
Exit using the command ctrl-X.

Part 3: Looking at files and directories

Unix systems provide a tree of directories with files in them---the same basic abstraction that you find in more recent systems such as Microsoft Windows or MacOS.

The directory at the top of the tree is called the root directory and it has the name / (pronounced, if you must, as `slash'). To look at its contents, type
ls /
This will list what is in the root directory. You'll see a bunch of strange names there, something like:
Image            emul             mnt              scilab
Projects         etc              netbsd           source
altroot          home             netbsd.old       stand
backupA          homeemp          proc             sys
backupB          homestu          rescue           tmp
bin              kern             restoresymtable  usr
boot             lib              root             var
dev              libexec          sbin             win2000
If you type instead
ls /netbsd
you'll see only one name listed, because /netbsd names a file, not a directory.

Every program running on a Unix system also has a current working directory, where it looks for names that don't start with /. Your shell is no exception; it will print the full name of its working directory in response to the command pwd. Do that now, and you should see something like
/homestu/wthunder
if your user name were wthunder. You might guess, then, that /homestu is a directory full of students' home directories.

A name with slashes in the middle of it describes a path through the tree to reach a particular directory or file. In the example above, the initial `/` says to start at the root, and follow the link named homestu, then the link wthunder. A name with several components is sometimes called a pathname.

Change your directory with the command
cd /scilab/share/cgray/tutorial/2
(Keep in mind that you can always go home with the command cd (with no arguments).)

Recall that when you do ls -a you see that that several more names show up, all beginning with a period (``dot''). Two of these names are special:
.
(dot) is another name for the directory itself, and
..
(dot-dot) is a name for its parent---the directory above it.

Part 4: Manipulating files and directories

So far we have looked at files and directories that already exist, but we haven't talked much about how to modify them or create new ones.

1. Making and removing directories

The command to make a new directory is
mkdir new-dir-name

The name will be interpreted just like any other name: if it starts with `/' it is absolute; otherwise it is relative to the current directory. Also, make sure you are in your home directory.

As you work through this tutorial, you will be creating and removing a bunch of files. First, you'll want a directory for all your work in this class; then you'll want a subdirectory particular for this assignment. (First, make sure that you are in your home directory.)
cd
mkdir cs241
cd cs241
mkdir assign1
cd assign1
Keep in mind that most Unix commands for manipulating files do not print anything when they work---they only complain when they don't work. Change the current directory to your newly created directory and list all of its contents; it should contain only the `.' and `..' entries. Make another directory there named foo.
mkdir foo
On Unix, you don't delete files/directories, you remove them---meaning you remove them from the tree of directories. The command to remove a directory is rmdir, followed by the names of directories to be removed. Remove foo now.
rmdir foo
Make a new directory named baz, and then make a directory named bar in baz with the command
mkdir baz
mkdir baz/bar
List baz to verify that you've made the directory inside it.

You cannot remove a directory unless it is empty. Try to remove baz now; you'll get an error message
rmdir: baz: Directory not empty
Without changing your directory, see if you can remove the two directories.

2. Managing files

Caution: Unix commands generally assume you mean what you typed. Unless you explicitly ask for it, there won't be any ``Do you really want to do this?'' prompts. Also, what's gone is gone: there is no undelete or other undo command to back out of doing something. So get in the habit of thinking and proofreading before you hit the ``Enter'' key.

You'll usually create files with an editor (XEmacs) or some other program. You can also copy an existing file with the cp command. Its simplest form is just
cp fromname toname
You should still be in your assign1 directory. Copy a file to work with:
cp /scilab/share/cgray/tutorial/2/foo/file1 quux
A listing should show that you now have a file named quux in the current directory. Make another copy of it with
cp  quux quux2
Now try copying the new file back on top of the old one:
cp  quux2 quux

Use ``ls -l'' -- this gives you not only the listing of files, but also some information about them. One thing you'll see is the time the file was last modified. You'll notice that copying sets the time to when the copy is made.

You rename a file by moving it:
mv quux2 foo
Both mv and cp can be given a directory as the destination (second argument), in which case the file is moved/copied to the same name within that directory. So now try:
mkdir dir
cp  foo dir
mv  quux3 dir
Use ls to make sure you understand what happened.

Finally, cp can be used to copy a directory and everything it (and so on for any directories in it) by giving it the `-R' flag (for recursive). So to copy the provided directories from tutorial 2, you could use
cp -R /scilab/share/cgray/tutorial/2 .
(don't miss the dot as destination) to give the new directory the name 2. You can also give it a new name. Try
cp -R /scilab/share/cgray/tutorial/2 example
Make sure you understand what happened.

To turn in

A couple more commands will be useful for turning assignment in because they can be used to prove that you've done the work. The first is the script command.
script (filename)
This will record everything you type and everything else printed on the terminal, storing it in the filename you give. If you leave off the filename, it will automatically create a file named typescript. When you're done with the work you want to record, type exit.

The second is the cat command. It dumps the contents of the file to the terminal. Try
cat /scilab/share/cgray/tutorial/2/foo/file1
Finally, in order to turn in your assignment by email, we recommend you use the Unix email program pine. It has the same look and feel as pico. Just type pine, and hit 'C' to compose a message. When you are in the body of a message, use ctrl-R to import a file into the body, and ctrl-X to send.

Now, to prove you've done the work in this tutorial do the following
To log out on the console, press the left mouse button while pointing at the background, select ``Exit Fvwm'' and then ``Yes, Really Quit''. You'll know you've logged out when you get the login screen you saw at the beginning.
Thomas VanDrunen
Last modified: Wed Jan 26 09:16:39 CST 2005