Chapter 1: Introduction
If I put text here will the title above show?
1.1 Unix flavours
Unix originates in AT&T's Bell Laboratories in the early 1970's. With the success of the UNIX operating system many computer vendors started marketing their own versions of the UNIX system optimised for their own computer architectures.
Some flavours of UNIX are commercially available and some are available for free.
1.1.1 Available commercially
Solaris – Sun Microsystems’ implementation, of which there are different kinds.
AIX – IBM’s implementation, short for Advanced Interactive eXecutive.
SCO UnixWare and OpenServer – are implementations derived from the original AT&T Unix® source code acquired by the Santa Cruz Operation Inc. from Novell, and later on bought by Caldera Systems.
BSD/OS – the Berkeley Software Distribution (BSD) Unix implementation from Wind River.
IRIX – the proprietary version of Unix from Silicon Graphics Inc.
HP-UX – short for Hewlett-Packard UniX.
Tru64 UNIX – the Unix operating environment for HP AlphaServer systems.
Mac OS – Mac operating system from Apple Computer Inc. having a Unix core.
1.1.2 Available for free
FreeBSD – derived from BSD, it is an advanced OS for x86 compatible systems.
NetBSD – Unix-like OS derived from BSD and developed by The NetBSD Project.
OpenBSD – multi-platform 4.4BSD-based Unix-like OS from The OpenBSD project.
Linux — a Unix-type OS originally created by Linus Torvalds, the source code of which is available freely and open for development under GNU General Public License; there are numerous Linux distributions available
1.2 MacOS
The MacOS operating system consists of a UNIX kernal, and all the GUI stuff you see on the screen, and plugin functionality for the system to talk to components.
The MacOS operating system is written in Objective C. The UNIX kernel is written in C. The IO PnP subsystem is written in Embedded C++.
Since the UNIX kernel is written in C, when interacting with UNIX in MacOS, you are simply running C programs.
1.3 Terminal
MacOS comes with a built in command line interface called Terminal. It presents you with a window and place to type text. The text you type is usually the name of a program followed by the information that program requires to run.
In UNIX the programs we are running are compiled C programs.
1.4 Executing C programs in terminal
Executing a C program in terminal is as simple as entering the program name at the terminal prompt and hitting enter.
C programs take options and arguments (often called parameters.) They are always entered in this order:
command -options parameters
Dashes are used to denote options, which modify the behavior of the command. Arguments without dashes denote the main parameters of the command, often these are filenames.
Single hyphens usually introduce options consisting of just one letter. Multiple such options can be grouped together, so ls -a -l
can be abbreviated as ls -al
. This was the standard convention for most early Unix commands.
Double hyphens introduce options that are whole words. This convention is necessary to distinguish them from the grouping described above. This option style was popularized by the GNU versions of utilities, because they often had so many features that they ran out of mnemonic single letters.
Sometimes an option requires a parameter of its own. The styles of this vary: some commands use -o parameter
, some use -oparameter
, some use --option=parameter
, and some allow multiple forms.
There are also a handful of commands that invented their own, ideosyncratic argument styles. These are typically very old commands, from before there was a concensus on argument conventions. Examples of this are tar
and dd
.
find
is also unusual in being an old command that used full word options before the —
convention was created; its arguments are practically a language of its own, because it's needs don't fit into the typical command -options parameters
paradigm.
Other reasons for variation among commands is that Unix did not originally have an argument parsing library function. It wasn't until well into its lifetime that the getopt
and getopts
functions were created. Using these libraries essentially forces you to follow common practices. But older programs did their own, ad hoc argument parsing, and different programmers made different decisions.
1.5 Getting Help
For the rest of this book we'll be looking at UNIX programs that run in MacOS terminal. When you want to know more about a given program simply run man
man ls
To go to the next page press spacebar
. If this doesn't work, press Control-B to go back a page, and the spacebar, or Control-F, to go forward a page.
To get out of man
type q
.