Lab 1
The goal of this lab is to familiarize you with the system
in the computer science lab.
Even though you will be doing no programming in this lab,
you will work with a partner in a manner similar to how
you will pair programming starting next week.
These instructions periodically tell you to switch roles, but
the important part is that you switch periodically so that you
each practice all the concepts.
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.
First, dicide which one you initially will be the driver and which
will be the navigator.
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
last initial followed by your 5-digit student id.
(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.
Switch roles at this point.
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
Before you go on, switch roles.
The new driver should try each of the mouse-button menus.
Also, close the xterm and start a new one.
When you start an xterm, it connects the terminal to a program
called a command interpreter or, on Unix systems, a
shell. The shell displays 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 /etc
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
.
Now switch roles, or make sure the driver at this point is not the person
who is logged in.
Ssh also allows you to log in to another computer with a different user name.
While using another person's account is unethical in most cases
(and you should not give your password out to anyone),
it is possible that you would have an account on another machine
under a different user name.
Furthermore, when working in pairs, it may be necessary for the partner
other than the one logged into the terminal to have access to his
or her account.
That can be done using the "-l" flag in ssh:
ssh -l
(username) (machine name)
The machine may be the same one that you are sitting at.
Try running the same commands as before.
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. Switch roles, and 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.
Finally, there is a command that merely displays the contents of a file,
called cat.
Try cat'ing your file.
cat
(filename)
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
Switch roles before going on.
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 cs235
cd cs235
mkdir lab1
cd lab1
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.
Switch roles.
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 lab1 directory. Copy a file
to work with:
cp /homeemp/tvandrun/pub/cs235/Hello.java .
A listing should show that you now have a file named Hello.java in
the current directory. Make another copy of it with
cp Hello.java Hello.java2
Now try copying the new file back on top of the old one:
cp Hello.java2 Hello.java
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 Hello.java2 Hj
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 Hj dir
mv Hello.java dir
Use ls to 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
.
Second is a command to print a file:
lpr -P
(name of printer) (filename)
The name of the printer in the CS lab is sp.
Now, to prove you've done the work in this tutorial do the following
- Start a script.
- Move into the
dir
directory, if you're not already there.
- Copy the file you created earlier with XEmacs into
dir
- List the files in the directory
- Show the contents of the file you created
- Show the contents of
Hello.java
- Exit the script
- Print the script file and turn it in.
To log out on the console, press the left mouse button while
pointing at the background, select ``LOGOUT'' and then ``Yes,
Really Quit''. You'll know you've logged out when you get the login
screen you saw at the beginning.
Before you leave....
Each of you should change your password.
You should each log into a machine and do this separately.
To change your password, you need to be on cslab, not one of the
other machines, so open an xterm and ssh to cslab.
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.
Thomas VanDrunen
Last modified: Tue Aug 22 15:23:41 CDT 2006