Tuesday, May 27, 2008

Basic Features of UNIX

Some of the fundamental features of the UNIX System include standard input and output, pipes and redirection, regular expressions, and command options. Most of these concepts are found in DOS also, but in DOS they are relatively limited in scope. In the UNIX System they apply to most of the commands; in DOS they are only relevant to certain commands.

  • Standard I/O The concept of standard input and output is part of both systems. In both systems, the commands take some input and produce some output. For example, mkdir takes a directory name and produces a new directory with that name. sort takes a file and produces a new file, sorted into order. In the UNIX System, certain commands allow you to specify the input and output, for example, to take the input from a named file. If you do not name an input file, the input will come from the default standard input, which is the keyboard. Similarly the default standard output is the screen. This concept is relevant for DOS also. If you enter a DIR command in DOS, the output will be displayed on your screen unless you send it to another output.

  • Redirection Redirection is sending information to a location other than its usual one. DOS uses the same basic file redirection symbols that the UNIX System does: <> to send output to a file, and >> to append output to a file. An important difference is that DOS sometimes uses the > symbol to send the output of a file to a device such as a printer, whereas the UNIX System would use a pipe. For example, the DOS command

    C:\> dir > prn

    sends the output of the dir (directory) command to the printer. The UNIX System equivalent would be the following pipeline:

    $ ls lp
  • Pipes Both systems provide pipes, used to send the output of one command to the input of another. In the UNIX System, pipes are a basic mechanism provided by the operating system, whereas in DOS they are implemented using temporary files, but their functions are similar in both systems.

  • Regular expressions The concept of regular expression is used by many UNIX System commands. While the Search routine in DOS is limited to asterisks and question marks in searching files and folders, there are some counterparts in DOS in the JScript and VBScript routines. Regular expressions are string patterns built up from characters and special symbols that are used for specifying patterns for searching or matching. They are used in vi, ed, and grep for searching, as well as in awk for matching.

  • Options Most UNIX System commands can take options that modify the action of the command. The standard way to indicate options in the UNIX System is with a minus sign. For example, sort –r indicates that sort should print its output in descending rather than ascending order. Options are used with DOS commands, too. They are called command switches and are indicated by a slash. For example, DIR /P indicates that DIR should list the contents of the directory one page (screen) at a time, which comes in handy when you are looking at large directories. The concept is the same in both systems, but options play a more important role in normal UNIX System use.

No comments: