Building Unix Commands

One of the most confounding things for the Unix neophyte is being confronted with a complex Unix command. The cryptic nature of Unix is such that even the most seasoned Unix professional may have trouble deciphering such a command. Hidden in that complexity, however, is a great deal of power. In order to leverage that power for your day-to-day work, it's essential for you to learn how to deal with complex commands.

In this section, we will begin by examining a cryptic Unix command in order to see how it is really composed of many simpler commands. We'll then walk through the process of creating such a command in order to perform a specific task.

Regarding the terms commands and scripts, you should note that any command may become a script if it is encapsulated into a file for execution. Hence, find . -print can be a command if executed from the prompt, or a script if placed into a file.

Decompose a Complex Unix Command

This section shows how a Unix programmer can string commands together into a powerful one-line command. The following one-line Unix script performs an important Oracle function—it kills all Oracle background processes when the database cannot be shut down normally:

ps -ef|grep "ora_"|grep -v grep|awk '{ print $2 }'|xargs kill -9

At first glance, this Unix command appears to be a conglomeration of cryptic letters. However, this is actually a series of commands that are joined together using the pipe operator (|). Here's a view of the command that's ...

Get Unix for Oracle DBAs Pocket Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.