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 used by the workstations and multi-user servers within the school.

On X terminals and the workstations, X Windows provide a graphical interface between the user and UNIX. However, knowledge of UNIX is required for operations which aren't covered by a graphical program, or for when there is no X windows system, for example, in an ssh session.

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 (we will use the prompt $ in this tutorial).

The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have the 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 cursor keys to scroll up and down the list or type history for a list of previous commands.

The Directory Structure: absolute and relative paths

All the stored information on a Unix computer is kept in a filesystem. Any time you initiate a shell login session, the shell considers you to be located somewhere within a filesystem. Although it may seem strange to be "located" somewhere in a computer's filesystem, the concept is not so different from real life. After all, you can't just be, you have to be somewhere. The place in the filesystem tree where you are located is called the current working directory.

The Unix filesystem is hierarchical (resembling a tree structure). The tree is anchored at a place called the root, designated by a slash /. Every item in the Unix filesystem tree is either a file, or a directory. A directory is like a folder. A directory can contain files, and other directories. A directory contained within another is called the child of the other. A directory in the filesystem tree may have many children, but it can only have one parent. A file can hold information, but cannot contain other files, or directories.

When you first log into the Unix system, your current directory is your home directory. This is where your personal files and subdirectories are saved. Your home directory can also be referred to by the tilde ~ character.

To describe a specific file or directory in the filesystem hierarchy, you must specify a path. The path to a location can be defined as an absolute path, starting from the root anchor point, or as a relative path, starting from your home directory or from the current location. When specifying a path, you simply trace a route through the filesystem tree, listing the sequence of directories you pass through as you go from one point to another. Each directory listed in the sequence is separated by a slash. For example, the absolute path to the directory staff in the above tree diagram is /users/staff. The first slash indicates the root directory, and the second slash acts as separator between directories.

It is initially confusing to some that Unix uses the slash character "/" to denote the filesystem root directory, and as a directory separator in paths. Just remember, when the slash is the first thing in the path to the file or directory, the path begins at the root directory. Otherwise, the slash is a separator.

Unix provides the shorthand notation of "." to refer to the current location, and ".." to refer to the parent directory. Because Unix filesystem trees have no loops, the ".." notation refers unambiguously to the directory's parent. This allows us to specify relative paths.

For example, assumming that the current working directory is student, the relative path to the directory steve is ./../admin/steve. The first dot specifies the current directory; the next two dots take you one level up to the directory users; and the rest of the path takes you down to the steve directory. Notice that the leading dots .. represent the directory users in this example, which is why the name users is not explicit in the path.

Here is another example. Assumming that the home directory is jon, the relative path to the directory usr is ~/../../../usr. The first tilde takes you to the home directory; the next two dots take you one level up to the directory admin; the next two dots take you one level up to the directory users; the next two dots take you one level up to the root directory; then down to the directory usr. Note that without the tilde symbol in front, the path starts at your current directory, not at your home directory.


  1. Specify the absolute path to the directory named jon at the bottom of the tree diagram.

  2. Specify the relative path from the current directory student to the directory named admin in the tree diagram.

  3. Specify the relative path from the home directory jon to the directory named staff in the tree diagram.

M.Stonebank@surrey.ac.uk, © 9th October 2000