
By Augie Hansen
A Survey of students in my UNMIX system classes shows that
somewhere between one-third and one-half had prior experience
with DOS before attempting to learn about the UNIX system.
This range is significant, though not surprising, given the large
number of DOS-based computer systems, which some estimates place at
more than 20 million.
It is heartening that so many of you are converting to UNIX or
at least learning about UNIX as an alternative to DOS for some
computing tasks. If you're among those who are converting, this
month's column is for you. It describes the similarities and
differences between the two operating environments and summarizes
the major commands and application programs that you need to know
to obtain a reasonable level of proficiency.
To simplify the task, I assume that you have a basic knowledge
of DOS commands and files, knowledge that goes beyond having your
system come up running Lotus 1-2-3 or dBase. If you've used your
DOS system in a way that has prevented you from ever seeing the
DOS prompt, this month's column will be of little or no value to
you. Windowing and menu-style user interfaces, a topic for a
future column, will undoubtedly serve you better than a
command-oriented shell.
Commands Common to DOS and UNIX
Table 1 lists DOS and UNIX system commands that have similar
purposes in both operating environments-not identical behavior,
to be sure, but close enough for the commands to be considered
almost equivalent. Fundamental differences between the design
philosophies and capabilities of the two operating systems
preclude precise functional equivalence.
The DOS and UNIX system commands that have similar purposes in
both operating environments-not identical behavior, to be usure,
but close enough for the commands to be considered almost
equivalent. Fundamental differences between the design
philosophies and capabilities of the two operating systems
preclude precise functional equivalence.
The DOS and UNIX directory-related commands are very similar.
The primary difference is that the DOS MKDIR and
RMDIR commands can deal with only a single directory
name for each invocation.
The UNIX mkdir and rmdir commands
accept directory name lists,so a single command invocation can
create or delete multiple directories.
Under DOS, all file and directory names are converted to
uppercase on input. Such names are conventionally shown in all
capital letters, but you can type them with either lowercase o/////
uppercase letters. Most UNIX program names, on the other hand,
contain only lowercase letters, which you must type exactly as
shown because the UINIX system is sensitive to letter case.
The DOS CD command serves the purposes of two
UNIX commands. When invoked with a directory path name argument,
it acts lid cd, which changes to the specified
directory if the directory is correctly named. However,
CD without a directory argument displays the name of
the current directory, which is the function of pwd
(print working directory) under UNIX. The UNIX cd
command, when invoked without a directory argument, changes to the
user's home directory - a source of considerable frustration for
many DOS-to-UNIX converts. Of course, DOS has no notion of a home
directory since it's not a multiuser system like UNIX.
Several other DOS commands have identical names and purposes as
their UNIX namesakes, but not quite the same operation.
The following examples describe the differences you should be
aware of.
The DOS DATE command allows you to set and read
the system date value. A separate TIME command deals
with system time values. The UNIX date command
combines both the system date and time functions into one
program. Issuing a date command without any arguments produces a
fixed-length string that contains date and time information in an
abbreviated form, like so: Tue Jul 26 11:45:14 MST
1988.
You can use an optional format-control string argument with
the System V UNIX date command to alter the
presentation of the date and time information. A variety of
field descriptors determine the appearance of date and time
strings and permit you to extract the components of dates and
times individually. Each field descriptor is introduced by a
percent sign (5).
Listing 1 shows how you can use the and
%Tfield descriptors intermixed with free text to
customize the date/time output. The single quotes around the
format-control argument are required to present the entire
string, including embedded spaces, as a single argument to the
date command. If you need to print a percent sign in
the test, use two (%%) to turn off the characters special
meaning.
More detailed information about the date>date
command and all other UNIX commands is available in the UNIX
User Reference Manual. See the sidebar
for information
about the manual's organization and contents, and some tips on
how to use the manual effectively.
The DOS SORT command is a simplistic version of
the UNIX sort command. Both help you order text in
one or more files, but the DOS version is limited in its ability
to isolate text strings in portions of a line in a file and in
its ability to handle patterns rather than fixed strings.
Listing 2 shows how easy it is to create and use a database
under UNIX. A simple text file containing the data is created
with a text editor (or a word processing program). The file
contains the data organized for easy access. Each line is a
record. Each record is a collection of fields that are separated
from each other by a blank or some other other character that is
not likely to be part of the text of any field. I have used the
colon (:) as a field separator in the sample phone
list database file shown in Listing 2A. The default field
separator is a blank (space or tab).
The sort command without any sort-ordering
arguments prints the records out ordered by first name, which is
the content of the first field. The entire record, starting with
the first character, is used as a sort key unless you specify a
different key. The results of a simple sort on the the entire
record produces the output shown in Listing 2B.
To sort using a different position in the records, use an
offset to specify the starting field. For example, typing
sort -t: +1 phonelist sorts the records starting
with the last name field. The +1 option
syas to use the field offset by one from the left-most end of the
record (which has zero offset). The -T: option tells
sort to use the colon (:) as a field
separator instead of the default blank,
Note that sorting a file this way does not change it. It simply
displays the contents in the specified order. If you want to reorder
the original file, use command-line redirection of the output
(sort phonelist >temp) to create a temporary file;
then overwrite the original file with the temporary file
(mv temp phonelist). The UNIX sort
command also recognizes a -o option followed by an
output file name. In this case the output name can be the same as
the input name, as in sort -t: +1 phonelist -o phonelist
to sort phonelist ``in place.''
A Rose by another Name...
Other commands have different names in the two operating
environments but do approximately the same job. An example is
the DOS FIND command, which is similar to the UNIX
grep command. These commands help you find text in a
file or in a group of files. For example, suppose you need to
find all references to the word administration in a
set of files related to a project you are working on. You could,
of course, use an editor (or word processor) to open each file in
turn and use its built-in search feature to look for the word.
But there is an easier and faster way.
Use grep. This cryptic name is derived from the
ed editor terminology g/re/p,
which means do a global search (g) for a regular
expression (re-a text pattern) and print
(p) any lines that contain a string of characters
matching the pattern specified by re. Listing 2C shows a
command that does the job. The search for ``johnson'' finds one
matching line, which is printed in its entirety.
Caution: The UNIX system has a command named
find, too, but it has a completely different purpose
that has no standard DOS equivalent.
Both the UNIX find and grep
commands will be covered in detail in a future ``New to UNIX''
column about commands that help you find text in a set of files,
find files somewhere in the UNIX file system, and so on.
Reading the UNIX User Reference Manuals
The UNIX system is a large and complex product, and thousands of
pages of documentation are but one piece of evidence in support
of this claim. Beginning UNIX users are often put off by thesheer
bulk of this terse documentation.
Don't let the manuals overwhelm you. Once you know where to
look, most of what you need to know is there for the reading.
Learning where to look involves learning about the manual
sections, the permuted index, and the format of the manual
pages.
The cornerstone of the UNIX documentation library is the
various reference manuals. UNIX system vendors are free to
package them any way they wish, but most adhere to the original
spirit-if not the exact form-of the AT&T Bell Laboratories
reference manuals.
The reference manuals are divided into sections. Each section
has a primary intended audience. Nearly all sections are of
interest to a system administrator, whereas beginning users will,
at first, care only about Section 1 (Commands and Applications),
kand possibly Section 6 (Games) of the User Reference
Manual.
A few commands have few or no options, do very simple, clearly
defined jobs, and therefore, have brief manual pages. The
cd command is a good example. It takes a simgle
argument to specify the target directory, or none at all to
indicate that the target is the user's home directory
Some commands and applications are complex enough to require
many pages todocument their features and operation. Editor
programs are amojng the many in this categorym, along with the
user shells, programming language tools, and text processing
applications.
Other sections of the reference manuals contain information
needed by system and application programmers who need to know how
the operating system works and how to write programs that
interact with it. If you are a programmer, or intend to become
one, you will probably have your manual opened to these pages
frequently.
A permuted index is an index that shows words in a contextual
setting, helping you isolate one instance of a word from possibly
many in the document. Near the beginning of the UNIX User
Reference Manual is a permuted index that you should refer
to when seeking information about a topic.
A Permuted index entry points to a specific manual section and
identifies the manual page entry by its topic name, which is
usually a command or application programname. Pages are in
alphabetical order except for an introductory page or so that
leads off each section.
All manual page entries, which can span one or more physical
pages, have a running headerthat shows the command or application
program name in the upper left and right corners of each page.
The body of each manual page connsists of several parts, some of
which may be omitted: Name, Synopsis, Description, Example(s),
Files, See Also, Diagnostics, Warnings, and Bugs.
The headings are mostly self-descriptive, but a few need
further explanation. The Synopsis part shows the command or
application program as you would type it. This includes the
program name, any optional arguments, and any required
arguments-typically file names. The Files part lists the files
that a program uses and these are not necessarily related to
files specified on the command line. The Bugs part, called Notes
by some vendors, describes any known restrictions and
deficiencies that may affect your use of the program.
|