Introduction to UNIX Part 1

UNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since.

An operating system (OS) is software that manages computer hardware and (other) software resources and provides common services for computer programs. UNIX is a stable, multi-user, multi-tasking system available for servers, desktops, laptops, and mobile devices.

UNIX systems can have a graphical user interface (GUI) somewhat similar to Microsoft Windows which provides an easy to use environment. That said, knowledge of UNIX is required for any operations which aren’t covered by a graphical program, or for when there is no graphical interface available, for example, in an ssh session.

Wikipedia article about UNIX

Types of UNIX

Even though there are many different types of UNIX, they all share common similarities. The most popular varieties of UNIX are currently Apple’s OS X, Oracle’s Solaris (Used to be Sun Microsystems), FreeBSD, and Linux. There are other companies which have, or have had popular versions of UNIX in the past including Microsoft’s Xenix, IBM’s AIX, HP’s HPUX, Silicon Graphics’ IRIX, and Digital Equipment Corporation’s (DEC) Digital UNIX (later Tru64 UNIX).

The UNIX Operating System

The UNIX operating system is composed of three parts; the kernel, the shell and the programs or applications.

The kernel

From Wikipedia

The kernel is a computer program that manages I/O (input/output) requests 
from software, and translates them into data processing instructions for the 
central processing unit and other electronic components of a computer. The 
kernel is a fundamental part of a modern computer's operating system.

The shell

The shell is a command line interpreter (or command line interface; CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands that are typed in are programs and arguments to programs. When they terminate, the shell gives the user another prompt.

Typical (default) UNIX prompts are either a $ for bourne shell (and derivitives), or a % for C or TC shell.

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks that the username and password are correct, and then starts another program called the shell.

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 filesystem for the file containing the program rm(1), and then requests that the kernel, through system calls, execute the program rm(1) on the file myfile. When the process rm myfile has finished running, the shell then returns to the UNIX prompt, indicating that it is waiting for the next command.

The behavior of the shell can be customized by the more advanced user. Not every user must use the same shell, and there are many different shells available on the same machine. Currently, the most common shell is bash, but other popular shells include zsh, ksh, csh, and tcsh. Most popular shells offer certain features to assist the user with inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, many popular shells 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, or visually show you the collection of choices, prompting you to type a few more letters before pressing the tab key again. You only have to type enough to provide a unique name and the shell will be able to complete the rest.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, you can use cntl-p, or cntl-n (some systems will have properly mapped the cursor keys ‘up’ and ‘down’ to also do this) to move forward or backward through the history of previous commands that have been entered.

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:

  • a document (spreadsheet, image, etc.)
  • the code (text) of a program written in some high-level programming language such as c, perl, or fortran
  • assembly language, or binary digits (an executable or binary file)
  • a directory, containing meta information (information about itself or its contents), which may be a mixture of other directories (subdirectories) and ordinary files.

The Directory Structure

All the files (including directories) are grouped together in the directory structure. The filesystem is arranged in hierarchically, like an inverted tree (growth happens at the bottom). The top of the hierarchy is referred to as root and is written as a slash. Don’t confuse a slash (forward slash) - / with a backslash - \. They mean very different things.

{% graphviz dot { digraph filesystem { root [label="/",shape=box,style=filled,color=“grey”]; ubin [label=“bin”,shape=box,style=filled,color=“grey”]; lbin [label=“bin”,shape=box,style=filled,color=“grey”]; file [label=“file.txt”]; home [shape=box,style=filled,color=“grey”]; bin [shape=box,style=filled,color=“grey”]; louisk [shape=box,style=filled,color=“grey”]; usr [shape=box,style=filled,color=“grey”]; local [shape=box,style=filled,color=“grey”]; tmp [shape=box,style=filled,color=“grey”]; root -> bin; bin -> ls; bin -> cp; root -> home; home -> louisk; louisk -> file; root -> usr; usr -> ubin; ubin -> make; usr -> local; local -> lbin; lbin -> wget; root -> tmp; } } %}

Starting a UNIX terminal

On a Mac, you can find the application in /Applications/Utilities.

You should see something like this:

On other flavors of UNIX, or Linux, it will depend on what Graphical environment is installed. Currently, the most popular graphical interfaces are Gnome and KDE.

  • Gnome based system: its probably in the top left, under Applications -> Accessories.
  • KDE based system: its probably in the lower left (Windows style), K -> System, and called Konsole.

If you have something else, chances are you’re more advanced than needing this tutorial.