It appears there is a majority opinion of those responding that we should
start here, and perhaps move to another maillist in time. Someone
suggested that a web page would be more appropriate, and I consider that a
viable future option for archiving and eventually reaching a wider group.

I will preface my posts with the phrase UNIX INTRO. This will allow
uninterested users to skip these messages.

I believe in teaching some background as well as basic UNIX concepts. I
promise that we will soon get to the command line...

--------------
      The UNIX
    Philosophy
--------------

--------------
        Digest
--------------

One important difference between the UNIX and the Microsoft Windows
operating environments: With Microsoft you are limited by the software on
your PC. With UNIX you are limited only by your knowledge and experience.

Why is this true? If you aren't presented with an option in the Windows
graphical user interface (GUI) environment, you do not have a ready
mechanism for changing the situation. With UNIX (and especially Linux),
you generally have the opportunity to bypass, or even to modify what you
don't like.

The learning curve is steeper. But consider the example of a text search
for a group of words or a phrase. UNIX offers a built-in mechanism (the
grep command, and its several variations) to make your search flexible,
powerful, and recursive. In spite of efforts to simulate this power in a
Microsoft environment, there is really nothing comparable.

Suppose that your ethernet card isn't working properly. Want to discover,
in a matter of seconds, every reference to "eth0" in every document of
every directory on every partition of your entire system, then display
those results according to which files were most recently modified?
Simple!

Of course you must learn how to formulate the search command. And
understanding the underlying concepts of UNIX may take weeks, months, or
even years. But once that computing power is in your brain, the increase
in ability to pull key elements from multiple documents in disparate
directories will simply amaze your friends. And that is only one UNIX
"trick"; there are innumerable others. This is the "Wow!" factor of UNIX.
Welcome aboard!

--------------
      In-depth
--------------

------------------------------------------------------------------------
We'll cover more philosophy, plus using pipes to sort and select output.
------------------------------------------------------------------------

The text _The UNIX Philosophy_* by Mike Gancarz offers a comparison of
operating systems:

<quote>

An operating system, by its nature, embodies the philosophy of its
creators. The Apple Mac/OS, with its highly visual, object-oriented user
interface, proclaims "it's right there in front of you." Microsoft's
MS-DOS, the undisputed leader of the personal computer revolution, tries
to bring "a taste of the mainframe" to the desktop. Digital Equipment
Corporation's OpenVMS assumes that the user fears the electronic thinking
machine and must be given only a few powerful choices to accomplish a
task.

The creators of the UNIX operating system started with a radical concept:
They assumed that the users of their software would be computer literate
from the start. The entire UNIX philosophy revolves around the idea that
the user knows what he is doing.

</quote>

Why do we need a "philosophy" just to use a computer? Well, you don't--
not any more than you need to understand radio buttons, listboxes, or
modal dialogues to figure out a graphical user interface. But such
knowledge can help. 

In a UNIX environment, knowledge is even more useful. And because UNIX was
developed with certain concepts in mind, the more you learn and apply the
UNIX philosophy, the more productive your work will be.

When faced with nothing but a command prompt on the computer screen, the
neophyte may be at a loss for what to do. There is nothing to click,
nothing to select, possibly just a dollar sign prompt waiting patiently
for input.

The power in this situation comes from prior knowledge of commands to
execute, and flexibility comes from creativity in command construction.
Your mind becomes attuned to the system. You will learn to appreciate
brevity, precision, efficiency.

If you adopt the UNIX philosophy, you'll undergo a "paradigm shift".  You
will better appreciate issues such as how the efficient use of resources
keeps you and others from wasting time. You may perceive how SILENCE ON
SUCCESS not only becomes a given in everyday communication, you will
discover that the concept supplants and complements online courtesy.

                 ----------------------------------

WHAT? Silence on success? What on earth are you talking about!???

OK, OK, I'll get to that soon. I promise it will be worth the wait.

                 ----------------------------------

The text _The UNIX Philosophy_* (info below) offers 19 points which
encompass the concepts behind UNIX. We'll deal with (and perhaps embellish
upon) just a few of these.

  o Programs which are small run faster, conserve resources, and work well
as building blocks to create larger programs.

  o Programs work best if they are designed to do one thing well, rather
than many things that may not be needed by a user.

If you hang around computer users for very long, you are bound to hear the
term "orthogonal". The _New Hacker's Dictionary_* defines orthogonal as:

orthogonal [from mathematics] adj. Mutually independent; well separated;  
sometimes, irrelevant to. Used in a generalization of its mathematical
meaning to describe a set of primitives or capabilities that, like a
vector basis in geometry, span the entire 'capability space' of the system
and are in some sense non-overlapping or mutually independent..."

The UNIX philosophy (as opposed to, for example, what might be described
as the _Microsoft_ philosophy) is to provide a host of orthogonal
utilities for users. This means that there is one main display command
(cat), and also one main sort command (sort), and these may be connected
together by something called a pipe, so that displayed output may also be
sorted. The sort command may likewise be called by a mail program, a
database program, a news reader, or a user-written script.

In contrast, if Microsoft had designed UNIX, each mail and database
program would presumably have its own sort routine, and each sort routine
would be different-- customized for the particular application that uses
it.

What is the main consequence of the orthogonal design of UNIX? When a
programmer develops a new tool or utility, he/she doesn't need to worry
about compatibility with existing tools. This makes development
considerably easier than in the MS-DOS/Windows environment.

  o Data is best stored in a flat ASCII file. In the Microsoft world, this
means a text file. Text files are portable and easy to work with.

The Windows System Registry is an example of a system that does not follow
this concept. The registry is a binary file which controls all aspects of
Windows 95 and 98 behavior. While a binary file may allow faster access,
it is more vulnerable to corruption and requires much greater complexity
in the programs that access it.

  o Shell scripts are frequently the most appropriate way to code. A shell
script may not run as quickly as the binary file created by a C program,
but it is faster to create and easier to modify. UNIX users can study what
the script is doing, and modify as necessary.

  o Captive user interfaces in applications and in operating systems (an
example is Microsoft Windows) should generally be avoided. In the Linux
world, there are various interface choices-- the choice of Gnome and KDE,
various window managers, or the naked command line is but one example.
Sorry, you can't have choice of interface with Microsoft.

Some additional UNIX principles are more subtle, but no less important.
The following are essential concepts that we'll explore further.

  o Programs work well together if they are designed as filters. A filter
can take input, process it, and pass it on to another program. Again, the
building blocks concept.

  o Terse commands and silence on success provide an efficient and
powerful command line interface (CLI). This is one of the most difficult
aspects of UNIX for new users. It is also one of the most subtle but
powerful differences between UNIX and other operating systems. Keep
reading.

                 ----------------------------------

If you participate in a high-powered maillist for advanced UNIX issues,
you are likely to note some differences from your average list:

    > Messages are often brief and quick reads.

Extraneous info is left out. The first screen of each email typically
gives an overview of the entire message. Senders make good use of white
space and short paragraphs.

    > Quoting is precise.

You will not see three pages of quotation, followed by "I agree" or
"Thanks". Only the couple of sentences being responded to are quoted.

    > Appreciation for results is taken for granted. 

Thanks is understood, and helpfulness is repaid by the recipient helping
others.

    > The subject is always relevant. 

No one posts vague message subjects such as "help me", or "a good idea".
Rather, you'll see specific, informative subjects such as "Oracle 8 on
Linux" or "Proposal for New Windowing Software".

Do these practices require extra time? No, they save time. The little bit
of extra effort expended by the sender to trim the quotes and craft the
message are repaid a hundred times over when a hundred others read that
message. 

Likewise, no one gets upset if they do not receive simple thank you
emails-- after all, the time to read such emails is put to better use
solving new problems. This is "silence on success" in online
communications. (Such instincts are learned in time, and they frequently
distinguish the experienced online pro from the new guy.)

                 ----------------------------------

It is like this with the command line interface. We don't NEED to know
that an operation was successful, we only need to know when it failed.
And THAT is silence on success in command execution.

Commands *are* capable of telling us when they fail. Suppose that we try
to list something:

$ ls this.file.does.not.exist
ls: this.file.does.not.exist: No such file or directory
$ 

We tried to list a particular file with the ls command, and our command
failed, sending "No such file or directory" to the screen.

Now consider this example:

$ ls 
apr.19
feb.03
jan.01
jan.10
jan.12
jul.01
mar.22
sep.01
$ 

We list a group of filenames. These are clearly dates, but they appear in
alphabetical order (the default of the ls command). Notice that we get
ONLY the output of the ls command. There is no success message stating,
"this is the output of the ls command". Such a message would get in the
way of what we want to do next.

We will use a "pipe" symbol to pipe the output of the list command--
exactly what you see above, and nothing more-- to the sort command:

$ ls | sort -M
jan.01
jan.10
jan.12
feb.03
mar.22
apr.19
jul.01
sep.01
$ 

The -M switch to the sort command creates output in order by month.

The | is a pipe. It takes output, and sends it to another command's input.

But suppose we want all filenames with dates on the first of the month
(maybe bills are due?). So we use sort as a filter, piping the output of
sort to the grep command. The grep command will print ONLY those lines
that include our "grepped for" text:

$ ls | sort -M | grep 01
jan.01
jul.01
sep.01
$ 

Voila! Using the pipe commands, our output from the LIST command "ls" is
filtered through "sort" and then through "grep" to give us just what we
want, and nothing more: a list of filenames sorted by date, including only
the dates for the first of each month.

ls is a program, and so is sort, and so is grep. The pipes are a feature
of the shell, but we'll learn about that later.

                 ----------------------------------

Review:

  o Small programs called by terse commands. 
  o Pipes and filters. 
  o Silence on successful completion. 

All these are part of the UNIX way of doing things.


  _______________________________ end ___________________________     

References

The _New Hacker's Dictionary_ is otherwise known as the "Jargon File"

  http://www.tuxedo.org/~esr/jargon/

                 ----------------------------------

The _The UNIX Philosophy_ copyright 1995 by Mike Gancarz, Digital Press,
ISBN 1-55558-123-4

                 ----------------------------------

best wishes,

richard myers

Reply via email to