An Introduction to Linux

The aim of this document is to get you started with the basics of Linux.

Booting up Linux and logging in

Our computers can be booted up in Windows or Linux. If your machine is running Windows you will need to reboot the computer by pressing the keys Control-Alt-Delete simultaneously. You will then be presented with the option to log in under Windows 2000 or to shutdown and restart the computer - select the latter. After resetting itself the computer will prompt you for the operating system you wish to use, select Linux. When you eventually get the login prompt enter your username and password.

You will now be logged in. On the top left of the screen you will find a 'Red Hat' icon. This is equivalent to the Windows 'start' button. Clicking on this will open up a number of menus giving you access to various applications.

For example to start up the Firefox browser select Applications-Internet-Firefox. If you are prompted for a proxy username and password you can simply select cancel. This is only needed if you want to access web sites outside of PARNET.

At the top left of the desktop you will see an icon of a folder labeled 'Home Directory'. If you double click on this a file manager window will open up. This will be similar to Windows Explorer and you can use this to find files, and copy, move, rename and delete files. In this window you will also notice a folder labeled '..' clicking on this folder takes you up to the parent folder.

Logging Out

It is important that you remember to log out when you have finished your session. To do this click on the 'Desktop button' on the top of the screen and select logout. The computer will then return to the login window.

Some Basic Unix

In the Macintosh and Windows environments you can 'double click' on a program's icon to start it. This also works under Unix under the current window managers, however much of the time under Unix you run a program by typing in its name along with any arguments that it may use into a terminal window. As people don't seem to like typing long program names many Unix program have short (and sometimes cryptic) names. In Unix files are organized in directories which are equivalent to Windows or Macintosh 'folders'. File types are usually denoted by their endings. For example a file with a '.java' ending normally indicates that it is java source code, a '.m' ending indicates a MATLAB source file.

Basic Commands:

(Note all 'commands' are in fact programs in their own right)

Commands are entered into terminal windows (like the MSDOS prompt window). Open a terminal window by double-clicking on the computer monitor icon on your desktop. Alternatively you can get a terminal window by selecting the 'Red Hat Applications' menu and then selecting 'System Tools'. When you open a terminal window you will be placed in your home directory. This is the directory in our system where you will keep your files.

The basic operations that you want to perform in any operating system are file copying, renaming and deleting, the ability to move between directories/folders, and the ability to list the contents of a directory/folder.

On-line Help:

From a terminal window to find out about any Unix command/program use the manual command
> man program_name

> man ls              - will tell you about the ls command
If you don't know the name of a command you can try looking for manual entries via a keyword
> man -k keyword   This will list all programs that man thinks might
                   be relevant to your keyword (often more than you want)
eg. try
> man -k print

Developing MATLAB programs under Unix

MATLAB provides a nice integrated development environment under Linux. When you invoke MATLAB by typing
 >matlab &          (I suggest you run it in background)
a large window will pop up. This will contain 3 sub-windows; a command window, a command history window and a launch pad window.

The launch pad window allows you to browse and launch existing MATLAB programs by double clicking on them rather than typing their names into the command window. The command history window records all your commands, previous commands can be edited and reused by double clicking on them. However, previous commands are always accessible to you from the command window via the arrow keys or (Control-P).

I practice I prefer to close the command history and launch pad windows, and only use the command window.

Editing M files

MATLAB source files are known as 'M files', they are simply text files that have a name with a '.m' ending. The main MATLAB window has a file menu which allows you to open a new M file or open an existing one. This pops up MATLAB's text editor which is straightforward to use.

emacs

You do not have to use MATLAB's text editor to create M files. There are many text editors available under Unix. You may choose to use 'emacs' (though you are welcome to use any other if you wish). Emacs is a very powerful editor and is widely used. We have configured it so that it recognises MATLAB files and performs appropriate syntax highlighting.

Many programs 'understand' common emacs command for modifying text. For example, Firefox, the terminal window, and the MATLAB command window will respond to basic emacs commands.

For example to create and edit a file called script1.m you would type the following command in an terminal window

  > emacs script1.m &   ( run emacs in background)
In the emacs window you can then type in a simple MATLAB script. To save your program select 'Save Buffer' under the 'Files' menu. (You can also save the file by typing Control-x-s, that is type x and s while holding the control key down)

For more information on how to use emacs you can select 'Emacs Tutorial' from the 'Help' menu. It will take you about 15 minutes to run through the tutorial.

When you type in a program, save it, and then try to run it in MATLAB you will inevitably have an error. You will get a message giving the line number in the file where the error occured. To fix the problem go to your emacs window and edit the file. There is a shorthand way to get to a desired line, type Esc g. At the bottom of the emacs window you will be prompted for the line to go to - go there and fix your error(s). Save the corrected file (Control-x-s). Move to the terminal window running MATLAB and try again...

Experiment, have fun...

Don't forget to log out