UNIX Introduction

This session concerns UNIX, which is a common operating system. By operating system, we mean the suite of programs which make the computer work. UNIX is the operating system at the core by all current generation Macintosh Computers.

The Macintosh operating system, called OS X, has a very elegant a graphical user interface (GUI) between the user and UNIX. However, knowledge of UNIX is required for operations which aren't covered by a graphical program.

The UNIX operating system

The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

The kernel

The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.

As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt $ to the user, indicating that it is waiting for further commands.

The shell

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt ($ on our systems).

The adept user can customize his/her own shell, and users can use different shells on the same machine. The default on Mac Unix systems is bash shell by default.

The bash shell has certain features to help the user inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the bash shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the up and down arrow keys to scroll up and down the list or type history for a list of previous commands.

Files and processes

Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers etc.

Examples of files:

The Directory Structure

All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root.

The Unix file structure

In the diagram above, we see that the directory physics contains the subdirectory foobar and a file proj.txt.

Starting an Terminal session

To start an Terminal session, launch the Terminal application. It is found in the Utility folder in the Applications folder. (You can drag the Terminal application to your Dock to make it easy to find in the future.) When you launch the Terminal application a window will appear with a Unix prompt, waiting for you to start entering commands.

An terminal window at the Unix prompt

Using the X Window System

Mac OS X uses a window system called Quartz for its GUI. Quartz was developed by Apple specifically for OS X. Most UNIX systems use the X Window System or X11. Macs are also capable of using X11. A huge amount of scientific software has been developed to run under X11 so you will find it useful to learn how to launch it on a Mac.

Programs that run under X11 are called X clients. X11 serves these programs by drawing windows on the screen, handling mouse clicks, etc. To launch the X11 server, simply find the XQuartz application Applications folder and double-click it. This will launch the server along with an X client called xterm which is just a window where you can enter Unix commands. It looks much like the Terminal window. Don't let this fool you though. When you run XQuartz you launch the X11 server so that any programs that need X11 can now draw things to your computer screen.

An xterm window and X11 menu bar

 

Adapted for Mac OS X by Shane Burns from a tutorial by M.Stonebank@surrey.ac.uk, © 9th October 2000