Unix Essentials Class

Introduction · Table of Contents · Unix vs. other operating systems · Getting Started · Fundamental UNIX Concepts · Unix Files · Directories · Introduction to the Korn Shell · The vi editor · Korn Shell Again · Hyper-Ad Home Page · Technical Tutoring Home Page · Recommended Books · Online Store

UNIX vs. other operating systems (OS)

A. Multi-user OS
B. Powerful command line interface (the shell)
C. Hierarchical File System
D. Open Architecture (GNU and Linux, Open BSD)
E. Free and readily available software

UNIX was developed in the early 1970's at AT&T Bell Labs. By the 1980's, there were two major branches of UNIX, the Berkeley Software Distribution (BSD) and the System V Release 4 (SVR4). Modern systems mix these variants and "lean" toward one or the other:

System V Release 4 (SVR4) - like systems:

SCO UNIX (now defunct)
Sun Solaris *
Hewlett-Packard HP-UX *
IRIX

Berkeley Software Distribution (BSD) - like systems:

Digital UNIX
Sun OS (now defunct, replaced by Solaris)
Linux*

Roughly even mixture of both BSD and SVR4:

AIX*

* denotes an OS worthy of your attention

The differences between these systems have mostly to do with how they deal with hardware and networking. The shells (the most important interface to the user) are virtually identical, so learning the basics on one flavor of UNIX carries over very well to the other flavors of UNIX. The implementation-dependent parts of each operating system are usually learned on the job; we will ignore these details when possible.

UNIX has the following advantages compared with other operating systems:

    1. excellent use and control of system resources
    2. very high reliability (long uptimes between reboots)
    3. tools for customizing the system are either native and bundled with the operating system or are easily available free
    4. in the case of open source systems such as Linux, no software licensing hassles for commonly used software
    5. far better scalability than any other OS, save (maybe) for mainframe systems
    6. readily available, searchable, complete documentation both on the system and online via the Internet
    7. massive stores of free software available for downloading and building

Typically, UNIX systems can operate continuously for hundreds of days without being rebooted. There have been many cases of UNIX servers that have run for years continuously. Contrast this with Windows NT, for example - Microsoft recommends rebooting NT servers every month. The stability of UNIX is one of its biggest advantages.

A. Multi-user OS

All flavors of UNIX are multi-user systems; a number of users can have accounts on one machine and even use it simultaneously if hardware allows. In fact, many of the parts of the operating system are organized with multiple different users in mind.

The most powerful and important user on any UNIX system is the root user. This is the account for the system administrator and has all possible privileges to all parts of the machine.

The root user is usually the one responsible for:

    1. keeping the machine up and working properly
    2. setting disk quotas (limits on the amount of hard drive space each user can write to)
    3. permissions for use of software on the machine (so ordinary users cannot wipe out each other's work or take over control of the computer)
    4. installing software for global (everybody's) use
    5. applying software patches when bugs are found and fixed
    6. setting system policies (like security and access control)

If you have your own system, then you are the root user of your system. Since the root user can do a great deal of damage if not careful, the root user account is normally reserved strictly for system administrator tasks. Even if you own your own machine, you should make yourself an ordinary user account for everyday use so you don't accidentally break something. If something goes wrong with a multi-user system, the root user is usually blamed for it!

We will examine some of the user accounts later on in the course, but most of our work will be with an ordinary user account called student.

If there are a lot of users on a particular UNIX machine, then the concept of groups becomes important. Collections of users with similar needs are typically organized into groups, each with its own rules and group permissions. For example, a company might have all its UNIX users organized into groups by the department in which the users work, so the groups might be administration, accounting, research, testing and development. Each of these groups would have a different set of privileges, perhaps different set of specialized programs they are allowed to use, and a different set of files on the computer they are allowed to access.

By way of contrast, most Windows (95, 98, ME) and other personal computer operating systems (MacIntosh) are not truly multi-user, since anyone using the computer can access all the files and programs on the computer. Windows NT and 2000 are true multi-user systems, with an entirely different set of operating conventions than UNIX.

B. Powerful command line interface (the shell)

When a user logs into a UNIX computer, a shell program is started up. The user talks to the computer through the shell by typing commands on a command line. We talk in terms of using a command line interface. Nearly all flavors of UNIX also offer a graphic user interface (GUI) as well, but the heart and soul of real UNIX is the command line.

Simple commands, such as moving files between directories and deleting files, are actually easier with a GUI interface, but complex commands and program development are far easier using the command line. Since UNIX is really intended for serious computing, most of the emphasis is placed on learning the command line.

There are five commonly used shells:

/bin/sh - the Bourne Shell. This is the oldest, least-common denominator shell with the fewest commands. Its design was frozen years ago. Some flavors of UNIX, particularly Solaris and HP-UX, use the Bourne shell as the default shell. Programs created with commands from the Bourne shell (called scripts) will run on some of the other shells (particularly BASH and KSH below). This shell is almost always included with all flavors of UNIX.

/bin/bash - the Bourne Again Shell, or BASH. This is the shell developed and maintained by GNU, AKA the Free Software Foundation. BASH is the default shell in Linux, and is an extension of the Bourne shell. This means that scripts developed in the Bourne shell will run in BASH, but BASH scripts will not necessarily run in the Bourne shell. All of the commands available in the Bourne shell are also available in BASH, as well as many more.

/bin/ksh - the Korn Shell, or KSH. This shell, another extension of the Bourne shell, was developed by David Korn and is in wide use, particularly in big UNIX houses such as IBM. The Korn shell is the default shell in AIX, and so is particularly important for us. Contains all the commands from the Bourne shell plus lots of extras. Again, Bourne shell scripts will always run in KSH, but the reverse is not necessarily true. Linux distributions and Cygwin sometimes are shipped without KSH. Fortunately, there is a freeware version available called the Public Domain Korn Shell or pdksh, which is downloadable in source code form (which means you have to build it yourself).

/bin/csh - the C Shell or CSH. Using the C shell is NOT recommended. Programming in the C shell is considered harmful. You have been warned.

The C shell is NOT compatible with anything, except perhaps the TCSH below. Ignore this shell completely, and don't work anywhere that uses this shell. Included in nearly all flavors of UNIX as a trap for the unwary.

/bin/tcsh - the TC Shell or TCSH - a useful extension of the C shell that is OK to use. I wouldn't waste any time learning to program it, unless the pay you get for doing so is great enough to compensate for the almost total incompatibility with other, more standard UNIX shells.

As you can probably tell, I am prejudiced in favor of sh, ksh and bash. The operation of these shells are similar (there is more difference between ksh and bash than between the others), they are considered standard, and you can find tons of already working scripts for these on the Internet.

Please note well: You can call any program on the computer from any of these shells, except the ones that are special to a different shell from the one you are using. For example, you can use the operating system command 'ls' from any shell, but you cannot use 'setenv' from the Korn shell because it is a weird C-shell only program. In almost all cases, choice of shell does not limit the operating system commands you can use, just the shell commands.

The reason bash and ksh are in such wide use is because they have very complete command sets, so you never need anything else.

C. Hierarchical File System

UNIX file systems look a bit like an inverted tree. At the top of the tree is the single directory /, the root directory. This corresponds roughly with Window's C:\ directory. Do not confuse the root directory with the root user! In some UNIX systems, the root user's home directory is /, but in others (notably Linux), the root user has a special home called /root.

Inside the root directory are the main directories where the UNIX files live. Nearly all of these also have directories inside them, and these subdirectories often have many levels of subdirectories of their own. Hence, UNIX has a hierarchical file system (directories inside directories) as opposed to a flat file system (as in the ancient MacIntoshes) where only one level of directory is allowed. Files in the computer have to be in some directory somewhere, even the root directory.

A few of the subdirectories of the root directory are pretty common to all UNIX systems:

/bin - system-wide executables go here

/dev - all the hardware device files go here

/etc - all system-wide configuration files go here

/home - users' home directories live here

/lib - for executable library files only

/tmp - for temporary files - this one can be cleaned out since no valuable stuff should be put here

/usr - this is where programs (non-system executables) live - usually the biggest directory because all programs used by everybody go here

/var - a special directory that contains print queues and other weird beasts

As far as I know, there is no limit to the depth of subdirectories - you can go as deep as you want. Practically speaking, it gets very hard to navigate very deep directory trees - IBM's company wide DCE network is a giant UNIX file tree that is so vast, you can get lost in it very quickly. More on this later.

D. Open Architecture (GNU and Linux, Open BSD)

Open architecture refers to non-proprietary systems that are developed by large groups of people, often in their free time, according to standards agreed to after lots of trial and error. Usually, open architecture operating systems are also available free for downloading from various sites on the Internet. Open systems have one of several related standard architectures, the specifications are public and software developed for a particular open architecture system translates rather well to another.

In particular, the software offered by the Free Software Foundation (GNU) is excellent. The vast majority of the Linux system is GNU software (Linus Torvalds wrote only the kernel, everything else is GNU or other freeware).

There is at least one other free UNIX-like operating system, Free-BSD and several similar variations derived from the BSD. These are in common use as Internet server systems, particularly web and e-mail servers.

Linux is now the most prevalent UNIX system in the world, with over 10,000,000 users worldwide and growing. As of the last time I looked, the commercial server market was still dominated by Sun Solaris, followed by AIX, then Windows NT/2000. However, it should be pointed out that more than half of all Internet servers are powered by Linux or other free, open-architecture operating systems.

E. Free and readily available software

The greatest single aspect of UNIX is that is was originally designed for an academic setting, where different users wrote useful programs and posted them for anybody's use. Thus, there is an incredible array of useful programs already written, available for free download and use. The only difficulty is that not every version of UNIX runs software designed for a different flavor of UNIX, especially when the software has to directly access the hardware.

In particular, if you try to run AIX on a PC, you will fail. If you try to run AIX software binaries on anything but AIX, you will fail. The hardware is different, and so the software won't work on a different computer.

The good news is that most flavors of UNIX come with COMPILERS, programs that take human readable source code (most often in C or C++) and transform it into appropriate binaries that will run correctly on your computer. Source code for many, many programs is readily available on the Internet, along with specific instructions for tweaking the software (configuring it) for each different common flavor of UNIX. In many cases, the same source code will compile and run without changes on all flavors of UNIX. In other cases, the authors of the software include configuration scripts that detect which kind of UNIX you are using, tweak the code, and then compile it for you.

This process is called building software, and is much more flexible than the installation process used with proprietary binary software (such as Microsoft or commercial UNIX programs). It's a bit of a pain to learn to build your own software, but the benefit is a nearly infinite source of free programs, much of it very well written. An additional benefit of open software for those with programming skills is the ability to modify the software to suit personal tastes or particular applications.