^CSE2304^ ^2003^

2003, Semester 1, School of Computer Science and Software Engineering, Clayton Campus, Monash University, CSE2303 and CSE2304

Practical Session 0, 10-14 March 2003: Introduction to Unix

In CSE2303 and CSE2304 you will be required to use the operating system called Unix. This operating system is more suitable for program development than systems such as Windows or MacOS which you may have already used. You will be using Unix extensively for the rest of your course, possibly exclusively by the time you reach third year.

Unix and Linux: Unix is a generic term referring to a range of operating systems that behave in much the same way. Many of them are commercial systems sold by different vendors. Linux is a freely-available version of Unix. For most purposes, you can use the names interchangeably.

Registering your Unix account: To get to your Unix account, you will need to register for it. Registration basically entails you getting your username and password, so that you can log in.

Your username is easy: It is the same three-to-five-letters-plus-a-number code, based on letters from your real name, that you use to log in to a Monash system or when you use AuthCate. Your username is in lower case (Windows is not picky about this, but Unix is).

To register you only need to visit http://www.its.monash.edu.au/cgi-bin/getpass and follow the instructions.

Have a pen handy, then enter the information you're asked for. Your username is the one that was talked about above. Remember that the year is four digits long. Write down the password shown on your screen. Your password should be in lower case (even if it is not displayed that way) - Unix is fussy about case.

You can only register this way once! If you do not get your password the first time, you'll have to follow the advice below.

If your registration fails: Sometimes, registration fails for no apparent reason. If that happens to you, there are two options open to you:

Now that you have your password, you can proceed to log in to your account.

Logging into Unix: Now you need to log in to Unix. This differs depending what campus you are on. The following applies to Clayton and Caulfield campuses. Check with your local ITS if you're elsewhere.

First, you'll need to find a computer that can boot Unix. If you're in a scheduled prac, the chances are good that the computer in front of you will do this.

Reboot the machine. While it is rebooting, there will come a moment when you are asked which operating system to load. Choose ``Linux'' from the list.

While the computer boots, it may display a lot of text on the screen. This can be safely ignored. What you are eventually looking for is a line that looks something like this:

   clay-b19g14a-10 login:_
with the cursor flashing at the end of the line. This is the login prompt; the computer is ready for you to log in.

At the login: prompt, type in your username, in lower case. You'll then be prompted for your password; type that in too, also in lower case. You'll now see a prompt like this:

with the cursor flashing to the right. (The format of this prompt varies greatly from Unix to Unix; yours is probably different.)

This prompt is called the shell prompt, and it's where you type commands in order to have them performed. The shell prompt is described in more detail in later sections.

Logging out: To log out, type exit (or logout) at the shell prompt, and press ENTER:

   clay-b19g14a-10> exit

The Unix Shell: A shell is a program whose job is to interpret a user's commands and to act on them. With MS-DOS, the shell is COMMAND.COM; with Microsoft Windows, it's explorer.exe (which handles your mouse clicks). On Unix, there are several different shells. The original one is called sh (the ``Bourne shell'', named after the person who created it). You'll likely be using an enhanced version of sh, called bash (which stands, in true computer-geek-humour style, for the ``Bourne-again shell''). The following examples assume that you are using bash, but even if you're not, the other Unix shells are pretty similar, and most of the command will work just the same.

Shells are quite simple programs, and cannot do much by themselves. Instead, they largely rely on invoking external commands to do most of their work.

The shell prompt: After you log into a Unix system, the shell starts automatically, and you are shown a prompt called the shell prompt. It may look something like this:

or like this:
   [user@clay-b19g13-10 user] $_
or even like this:

Whatever your prompt looks like, the following examples will use the latter % symbol. In other words, do not type the initial % symbol in when you are doing the following examples; it is the prompt.

Introduction to the X Window System: Unix as an operating system has its origins in about 1970, a time when there were few graphical user interfaces and no ``mice''. This is part of the reason why computer programmers use the word ``print'' when they mean ``display'': in those days, the display device was a noisy line printer.

Of course, technology has improved since then, bringing with it Graphical User Interfaces, such as X, Microsoft Windows and MacOS. Unix developed its own GUI, called the ``X Window System'', or just ``X''. (The developers of X do not like it to be called ``X Windows'', but people still do.)

When you log in to a Unix machine, you may start in a text-only mode, often called console mode. All Unix computers are able to support console mode, so it is the lowest common denominator. But most Unix machines now have sophisticated graphical modes too, allowing you to use X.

If the computer does not start with X already running, to start X use the startx command, of course:

   % startx

It may take up to a minute for X to fully load. What you see now depends on which window manager you are using.

The default window manager is called xfce. It is designed to be a lightweight, easy-to-use window manager that does not clutter your desktop.

xfce has a panel at the bottom which contains a number of icons for your most common applications. Each icon also has a clickable arrow above it, which expands to show more, similar, applications. To start an application, click on its icon.

There are four workspaces (virtual screens) called ``One'' to ``Four'', which effectively quadruples your working space. Click on the names of these workspaces to switch between them.

Exiting X: To exit X and return back to the console, you'll need to find the ``exit'' option in the main menu for your window manager. With xfce, it's the button in the panel that looks like a power switch.

Web browsing with Unix:. Netscape Navigator is probably the most likely web browser to be installed on a Unix machine. You can start it by simply typing netscape at the shell prompt, or by finding it in your window manager's program menu. Naturally, you need to be running X to use Netscape.

If you're familiar with the Windows or Macintosh version of Netscape, you'll be right at home with Unix Netscape. You should have little trouble if you're used to using other browsers such as Opera or Internet Explorer on Windows.

Online Unix Prac System

In order to complete this prac you need to visit the Online Unix Prac System and complete all the topics in the set called ``CSE2303/CSE2304 Prac0: Introduction to Unix''.

Logging In

If you have an AuthCate password and you can remember it, then visit:

and enter your AuthCate username and password.

Click on the ``Edit Sets'' link, and choose the set called ``CSE2303/CSE2304 Prac 0: Introduction to Unix''. You can additionally choose the optional topic set if you want some extra exposure to Unix. Click on ``Change Sets'', and you will see a list of topics.

Now, just go through each of the topics one by one, and do what they say. The Unix Prac System remembers which topics you have completed, so when you come back to it later it will remind you which topics you've already done.

Guest Login

If you have forgotten or never received your AuthCate password, you can still use the Unix Prac system, but it will not remember which topics you've done, nor will it present the topics in a logical order. The URL is:


The Prac' Problem...


The problem to be solved can be found under the set called ``CSE2303/CSE2304 Prac0: Introduction to Unix'' (above), or the topic Unix filter commands in the Unix Prac System. Every day The Age newspaper has a word puzzle (right) which involves finding all the words containing certain letters. The point of this exercise is to show how we can use standard Unix commands (e.g. sort, uniq, etc.), pipes (|), and redirection (< and >), to help in solving this kind of puzzle. In this exercise you will find all the 9-letter words which contain exactly the following letters: u, c, r, o, e, n, i, s, r.

  1. In http://www.csse.monash.edu.au/~lloyd/tildeProgLang/C/Recn/permuteString.c is a C program to permute a fixed string of characters "pops".
  2. Modify it to read a string of any length as a command-line parameter (see http://www.csse.monash.edu.au/~lloyd/tildeProgLang/C/Basic/commandLineSimple.c ) and permute the characters of that string.
  3. Write all permutations of ucroenisr, say, to file permutations by:
    % ./permuteString ucroenisr | sort | uniq > permutations
  4. Q: Why do we use uniq?
  5. Run spell on the file permutations and put the output in the file rejects, by typing:
    % spell < permutations > rejects
  6. Finally, to find all the valid 9 letter words type:
    % comm -23 permutations rejects
  7. Q: Why do we have -23 above?
Also do the following:
% man uniq
% man comm
% man sort
% man spell
and read the results carefully.

DWA, DP, LA, School of Computer Science and Software Engineering, Monash University, Australia 3800.
Created with "vi (Linux & Solaris)",   charset=iso-8859-1