9  The Unix nature

To get value from the command line, you need to understand the Unix nature. This is a way of thinking about software and its use that permeates the Unix operating system, and the systems, such as macOS and Linux, that derive from it. It is concisely explored in a Wikipedia article at https://en.wikipedia.org/wiki/Unix_philosophy.

Here are several key points covered in that article.

The commands that we cover here are generally very small and generally interoperate with each other through Input / Output (IO) redirection. Every device attached to a Unix-alike system has a corresponding file descriptor. Most commands accept text input and produce text output. Tasks can be accomplished by stringing a lot of little commands together.

An important consequence of going with the Unix flow is that, when things go wrong, it is likely that you will find the problems not in the commands themselves, but in the way they are strung together. For example, the Unix sort command has been heavily debugged and used by millions of people. There is little point in writing your own sort routine when you can just add the sort utility to your command pipeline. If the sorting doesn’t work as expected, you have a clue about where to look for the problem: in the task infrastructure, not in the sort code (which is publicly available should you wish to inspect it!).

A typical Unix construct may look like this:

cmd1 < sourcedata > tmp1
cmd2 < tmp1  > tmp2
cmd3 < tmp2  > tmp3
cmd4 < tmp3  > targetdata

This construct employs redirection of input and output, commonly called IO redirection. It allows you to examine the intermediate results of task parts before committing to a task pipeline like the following:

cmd1 < sourcedata | cmd2 | cmd3 | cmd4 > targetdata

In both cases, a series of small programs is used in concert to accomplish a task. The IO redirection operators: <, >, and | are explained in the fileIO module.

The configuration of a Unix system includes dotfiles, explained in the dotfiles module. To briefly introduce them, I will say that there are global configuration files that are run whenever a Unix-like system starts up. When an individual logs in, their dotfiles can override all these global configuration files. Further, if an individual develops a project, it can have dotfiles that override the individual’s dotfiles. So, the more local you are to a given task, the more local the configuration can be.