[lug] Newbie Column #3 - The Unix Philosophy

Wayde Allen wallen at boulder.nist.gov
Wed Jan 26 10:38:49 MST 2000


In addition to the modular design paradigm we talked about earlier there
are several other concepts that are somewhat unique to UNIX.  First of
all, the file system and kernel are designed so that everything in UNIX is
a file.  This is pretty important.  For instance, if you want to read the
keyboard you simply read keystrokes from the keyboard file (Standard Input
or STDIN).  If you want to write something to the screen you simply write
a file to the screen file (Standard Output or STDOUT).  Writing and
reading files to and from the disk uses the same commands.  You simply
copy files to the printer device file to print them, etc.. 

The other important UNIX idea is that no one can really write a single
program that does everything.  Rather, people using UNIX believe that it
is more effective to write very small simple programs that do very
specific tasks very well.  An added advantage is that small simple
programs are much easier to maintain and understand.  Each of these small
specific programs or utilities is typically thought of as being a tool,
and the overall collection of these programs can be thought of as a
"toolkit". Once you understand the toolkit concept, it is possible to
solve large data processing jobs by simply selecting and combining the
tools needed from your toolkit.

For instance, I was just sent a set of data (file.data) from the lab that
consisted of three columns of numbers.  If I want to extract the 2nd
column of numbers from the data file, all I need to do is type: 

   cut -d" " -f2 file.data

The -d" " modifier says that my data is space delimited (the numbers are
separated by a single space), the -f2 modifier says I want field 2.  When
I hit the return key the results should be sent to my screen (stdout).  If
I wanted to sort the data I could use the tool "sort" by typing: 

   cut -d" " -f2 file.data | sort

The vertical bar "|" is called a pipe, and is used to pipe the output from
the cut command into the sort command.  We'll talk a little more about
this later.  What is important, is that very complex tasks can be easily
solved by making use of a relatively small set of tools.

- Wayde
  (wallen at boulder.nist.gov)





More information about the LUG mailing list