Command Line Syntax
The syntax for the use any single utility in UNIX is:
command [options] [expression] [filenames]
command
The name of the utility to be used.
Example:
pwd Prints the name of the working directory
option
Many UNIX utilities have a number of options that may be stated on the command line. They are used to qualify the usage of the utility. Option flags are preceded by either a hyphen ( - ) or a plus ( + ) symbol. They may be stated separately or grouped together (if they are preceded with a hyphen and not suffixed by a qualifier).
Example:
ls -la Long listing of the names of all files in the working directory
expression
Some UNIX utilities require an expression on which to operate. For example, searching files for lines that contain a stated expression.
Example:
grep "UNIX utilities" unix_fund.notes
Find all lines in the file unix_fund.notes that contain the expression UNIX utilities
filename
Many UNIX utilities require a file, or list of files, on which to operate.
Example:
ls -la /usr/bin Long listing of the names of all files in the directory /usr/bin
If a utility is stated wrongly on the command line, most utilities will print an error message, stating the correct syntax of use.
Example: ls -%
This will result in the following being displayed on the screen:
ls: illegal option -- %
usage: -1ACFRabcdfgilmnopqrstux [files]
Multi-Processing
Most UNIX utilities are separate from the UNIX operating system. That is, they are separate programs (many compiled from C source files) and, so, act separately from the operating system. As such, when the utility is used on the command line, the shell program that is being used makes a copy of itself and hands that copy over to the utility to be run. In other words, every time a utility is used:
a. The user has at least two processes in operation: the original shell and the utility.
b. The original shell remains unaffected by any changes the utility makes to its own shell.
The original shell is called the Parent Process. The copy is called the Child Process or Sub-shell.
Tip:
There are several commands that are built into the operating system - such as cd (change directory). When executed, they do not use a sub-shell, but are run in the present shell. This is because they need to affect the present shell's environment - such as updating the Working Directory, in the case of the cd command.
Certain utilities - and application software - may produce a number of child processes when used. At all times, there is communication between a parent and a child. In most cases, a parent process will go into the Background while a child process is running, so that there is no more than one process requesting information from the keyboard at any time. However, a slow-running child process may be forced into the background, allowing the user to continue to do other things (see Section 8.12 for more details).
As there will be a number of processes running at the same time - created by the operating system as well as all users on the system - each has to have a unique method of identification. The method used is that each process is issued with a unique Process Identification Number (pid) on execution. Both this and its parent pid is stored with each process.
Continued...