(Continuation of Tutorial Session 2 (Part A) issued in hard copy)

Continue the interactive terminal session by following the instructions given on this web page. If necessary complete the tutorial in your own time.


On your current desktop select (click on) Applications from the Fedora tool bar, a menu will appear; select System Tools and then Terminal. A terminal window will appear of the form shown in Figure 1. Note that the window contains a dollar prompt (e.g. $). Remind yourself how to:

  1. Move a window by left buttoning on the title bar and, while holding the button down, drag the screen around the desktop.
  1. To resize a window left button on a corner of the window and, while holding down the button, increase the size of the box by dragging "outwards"; to decrease the size of a box drag "inwards".
  2. Iconify the window by clicking in the iconify title button. The window will shrink to a pictorial representation on the task bar. Left button on this icon and the terminal window will reappear!
  3. Now try maximising the window.

Figure 1: Example Fedora terminal window


When typing LINUX (UNIX) commands always use lower-case letters. Note also that the typographical conventions given in Table 1 are used in the following pages:


$ cal 1997

$ cal 9 1752

plane textYou type the text exactly as shown. For example: `echo hello world' means that you should type exactly these characters.
italic textYou supply the text. For example: `echo someText' means that you type "echo" followed by some text of your choice.
Press the "return" key.
Hold down the "CTRL" key while you press the "D" key.

Table 1: Typographical conventions

Try each of the following commands at the "dollar" prompt.

$ date

$ cal


Note that the result produced by the last command is not an error. When England switched from the Julian to the Gregorian calendar in September, 1752, 11 days were removed from this month. There were riots in the streets with people chanting "give us back our 11 days"!

As with the windows operating system when you log in you are automatically placed in your home directory. The name of your home directory depends upon your username. To find out the name of your home directory use the pwd (print working directory) command as follows:

$ pwd

This tells you the full path name of your home directory. To display the contents of your directory use the ls (list) command:

$ ls

2.1. Creating a simple text file

A "quick and dirty" way of creating a text file in LINUX is to use the cat command coupled with the greater-than output redirection operator. Try the following:

$ cat > myFile some text

You have created a text file, called myFile, in your home directory. Use ls to check that it is there. Now try:


$ more myFile

or simply:

$ cat myFile

The more command calls a "filter" for examining continuous text, one screenful at a time. The cat simple "scrolls" through text files. The distinction is not always apparent when viewing small files that can easily fit onto a single screen. There is also a command less which forefills a similar function to more.

2.2. Working with directories

The following command creates a working directory called COMP101 (you have probably already got one):

$ mkdir COMP101

The command "ls" will list the contents of a directory. To distinguish between directory names and file names try:

$ ls -p

The ls -p command appends a / character (forward slash) to directory names. We can copy or move files from our current directory to another directory using the "cp" and "mv" commands, however, we must indicate the path to the new directory. We can do this using relative path names. For example try moving the myFile file created in last week's tutorial to your COMP101 directory:

$ cp myFile COMP101/.

Note that the dot is used for convenience where we wish to keep the name of the original file. To "change directory" use the "cd" command. For example:


$ cd COMP101

To change to the parent directory of your current directory simply type:

$ cd   ..

(note the space between the cd and the ..). To change to your home directory type:

$ cd

without specifying a path (the default path is the relative path from your current directory to your root directory).

To delete/remove files type:


Be very careful when removing files, once removed it is extremely difficult to get them back (if at all)! If desired a directory can be removed using the command rmdir although this will only work if all files and sub-directories contained in the directory have previously been removed.

2.3. Wild card characters

Wild card characters provide a convenient short hand for specifying multiple file or directory names with one name. Two of the most useful wild card characters are * and ?. The * matches any string (sequence) of characters (including no characters), and the ? matches any one character. "cd" to your home directory and try the following:

$ ls myFile?

$ ls *


$ ls *.*

$ ls *.txt

$ ls myFile*

$ ls *file?

Wild card characters are useful when you wish to manipulate groups of files using mv, cp and rm. be very careful when using rm *!

(You can now delete your myFile.txt file --- unless you particularly wish to keep it!).

2.4. Redirection

In normal operation, most programs take input from the keyboard and display the results on the screen. These are known as standard input and standard output respectively. However, if a program produces a large amount of output, it might be desirable to catch this in a file instead. The shell provides this output redirection facility using the greater-than character >. We have just used the greater-than output redirection operator to provide a "quick and dirty" way of creating a file:

$ cat > myFile some text

We can use redirection with many LINUX commands. Try:

$ ls > out.file

$ more out.file


In the same way that you can redirect output you can also redirect input. Try the following sequence of commands.

$ echo 13 9 1997 > in.file

$ more in.file

$ cal < in.file

A similar idea to redirection is the LINUX structure known as a pipe. This runs two or more programs in such a way that the output from one is used as the input to another. A pipe is represented by the vertical bar (or pipe) character |. Try:

$ ls | sort -r

2.5. Command line history

The Fedora system (like the LINUX systems) keeps a record of recent commands given to it, and these can be recalled and re-issued. This can save typing when the same or similar commands are being used repeatedly. To this end the following can be used.

Up arrow Step back through command line history
Down arrow Step forward through command line history
Left arrow Move one character to the left of the cursor in the current command
Right arrow Move one character to the right of the cursor in the current command

Once the cursor is at an appropriate position we can insert additional characters or delete characters as desired.

Another useful feature of the LINUX command line interface is "name completion". If we start writing a file or directory name, for example:

$ javac HelloW

and pres the "tab" or "Esc" key, the control system will try to complete the name by matching the characters typed so far with the contents of the current directory. Thus in the above case we might get:

$ javac

Try it!

2.6. Cutting and pasting

Another way of saving on typing is to cut and paste. Find a command in your command history which should still be visible in one of you windows, place the mouse cursor at the start of the command (not the reference number), hold down the left button of the mouse and drag over it to the right. The command will be highlighted. Now release the left button, move the mouse cursor to another window and:

  • If using a three button mouse click the middle button.
  • If using a two button mouse click both left and right buttons simultaneously

You have just cut some text out of one window and pasted it into another. You can now execute the command if you wish. (You can also "cut and paste" from and to the same window). In a similar manner you can cut text from WWW pages.

2.7. Printing

To send a file to the printer type.

$ lpr filename

Print outs can be collected from a series of "output bins" located at the entrance to Labs 1, 2 3 and 4 (Figure 2). To find out which bin is yours consult the printed sheet "pinned up" by the output bins.


Figure 2: Printer "bins"


Many LINUX/UNIX email software packages exist. We recommend Evolution. We also suggest that when you have found a mailer you like you commit to that mailer. The reason for this is that most mailers create their own "mail" folder for incoming mail --- if you are using more than one mailer your mail will be distributed over several such folders. For example if you read your new mail (if any) using Evolution under Fedora it will be moved into an Evolution mail folder where it is likely that you will not be able to re-read your mail using any other mailer.


3.1 Evolution

To invoke the Evolution mailer simply single click on the Email icon on the tool bar. A welcome window will appear --- simply follow the instructions. For receiving mail the email server type is POP. The Host (i.e. the "pop" server) is the username,/TT> is your usual user ID (cs5??). For sending mail select SMTP, your "smtp" server is Experiment with the interface and try sending a message to your tutor!


In the last tutorial you created a Java program called In an appropriate terminal window change directory (cd) so that you are in the directory where this file "lives". To compile it invoke the Java compiler as follows:

$ javac


Assuming all goes well (if it does not consult your tutor) you will now have translated the Java code into Java Byte Code file called HelloWorld.class. Do an ls to check the file is there. Try "listing" it!

To run the program we must use the Java interpreter as follows:

$ java HelloWorld


Text editing under LINUX operates in a very similar manner to that used under Windows in the last tutorial using the PFE editor. There are a number of edirors available under Fedora. If you select Applications, Programming and then Software Development y0u will see a number of editors (all equally good) suitable for writing Java programs, for example jEdit. Note that jEdit when first inoked starts with a welcome window --- simply close this to reveal the editor window.


There also a number of editors that can be ivoked from a terminal window command line, try nedit.

Now try loading and modifying your file so as to change the output. (Note: if you save the file using a different file name you must also change the class name --- remember class names start with an upper case letter!)


You will notice three buttons at the top right hand corner of the title bar of the exceed window. The rightmost button will end your Fedora/Exceed session --- do not try it! The middle button allows you to resize the Exceed window to reveal the windows desk top underneath (to maximise the Exceed window click on the middle button again). The left most button inconifies the Exceed window so that the Windows desktop is entirely revealed (to return go to the task bar and click on the "Exceed" icon).


Switch from your LINUX desktop to your windows desktop (if you have not already done so). Click on the "start" icon on the left hand side of the task bar and then select the Command Prompt option (by clicking on it). A window will appear of the form shown in Figure 3. Note that the prompt H:\> indicates that you are in drive H: (your home directory).

To use this interface simply type commands in the same manner as described above for LINUX commands. Most Windows 2000 "DOS" commands are very similar to those encountered in LINUX (see Table 2). Note that DOS commands are not case sensitive so can be typed in upper or lower case.

Note 1: You can make use of the arrow keys when you wish to edit or repeat DOS commands in the same manner as under LINUX. However, there is currently (August 2003) no name completion facility).

Note 2: You might find that some DOS commands recognise only "short" DOS names, for example the file myTimetable.txt might be shortened to MYTIM-1D.TXT. The reason for this is that in the early days of the DOS operating system (a precursor to Microsoft Windows) file names could only comprise a maximum of 8 characters followed by a suffix comprising no more than 3 characters. There are still some DOS commands that operate using such short names. If necessary you can find out the short version of your file names by typing:

H:\> dir/x

echo someTextecho someText
datedateDOS command also affords opportunity to alter the date
timetimeDOS command also affords opportunity to alter the time
lsdir/wThe 'w' stands for wide
cdcddirectory paths in DOS are expressed using a backslash (\) instead of the forward slash (/) used in LINUX and UNIX
more, lesstype

Table 2: Comparison between LINUX/UNIX and DOS commands


Figure 3: Command prompt window


In the command prompt window change directory to wherever your Java file is stored. This can now be compiled and interpreted in exactly the same way as before. Try it! Note that you are not using the same compiler and interpreter you used under LINUX (although it appears that way), instead you are using a Windows 2000 Java compiler and interpreter.


If you have not already done so return to your Fedora desktop (click on the exceed icon on the Windows 200 task bar). To log off:

  1. Close down any applications that you may be running - Jedit, Evolution, Etc.
  2. Single click on the Log out icon on the Fedora tool bar and then select "OK" from the resulting log out window.
  3. After a short pause the "XDMCP Display Manager Chooser" window will now reappear, click on the exit button and then respond appropriately to the confirm prompt.

You have now logged out off the LINUX system (but not out of Windiows 2000). End your Windoes 2000 session in the same way as before.

You can use the computer system at any time in any lab which is free - check the timetables outside each lab before you enter - labs are sometimes reserved for tutorial classes such as this one.

Created and maintained by Frans Coenen. Last updated 04 October 2005