Utilities
The REAL/IX Operating System includes the standard UNIX
System V utilities. This chapter gives a brief description of the
most commonly used utilities; full information on these and other
utilities are given in the manual pages.
File Access Utilities
The following user commands are used for accessing and
manipulating files and directories.
- ls(1) -list the files and directories
- cat(1) -list the contents of a specified file on your
screen
- pg(1) -like cat, but list one screen at a time
- lp(1) -print a paper copy of a specified file
- mkdir(1) -make directory
- rmdir(1) -remove (delete) directory
- mv(1) -move (rename) a file or directory
- cp(1) -copy a file or directory
- rm(1) -remove (delete) a file
- pwd(1) -list the present working directory
- cd(1) -change directories
- ln(1) -link files
Editors
The REAL/IX Operating System supports a variety of editors:
- ed(1) is the line editor that is used in shell scripts.
- vi(1) (pronounced vee-eye) is the screen editor. ex(1)
is a separate editor that can be used in conjunction with vi to
replicate the global editing capabilities of ed.
- sed(1) is the stream editor.
When using ed and vi, you are always working
on a copy of the file in a temporary buffer; the disk copy of the
file is unaffected until you explicitly issue a w (write) command.
Consequently, if you make a major mistake during an editing session,
you can regain the unaltered file by issuing a q (quit) command
without writing the file.
ed
The ed(1) editor can be used on either a VDT
or a hard-copy terminal. Most new users prefer vi(1) for normal
editing tasks, but ed is still useful in shell scripts.
ed is a line editor; during editing sessions,
it always points to a single line in the file called the current
line. Unless you specify a line or range of lines, ed applies
each command you issue to the current line. When you access an existing
file, ed makes the last line the current line so you can append text
easily.
To begin an ed editing session, enter the command
ed filename. If this is a new file, ed will respond
"?new-file." If you are editing an existing file, ed
responds with the number of characters in the file. Once in ed,
you work in one of two modes: append mode or edit mode.
In append mode, you add to the contents of a file; in edit mode you
can display, delete, or replace text and move about the file. In edit
mode, you can use shell regular expressions for search and substitute
operations.
The basic ed commands are:
- a -append text after current line
- i -insert text before current line
- c -replace text in current line
- u -undo previous command
- . -end append mode and return to edit mode
- p -print current line
- n -display line numbers
- d -delete current line
- m -move lines from one part of the file to another
- t -copies lines from one part of the file to another
- j -join current line with next line
- r -read in text from another file to end of file
- w -write file
- q -quit editing session
<CR>; -move down one line in the buffer
- - -move up one line in the buffer
Lines can be specified to ed in the following ways:
- 1,2 -by absolute line number
- . -current line
- .= -display current line number
- $ -last line
- , -first through last line
- ; -current line through last line
- +x x lines forward in buffer
- -x x lines backward in buffer
- /abc first line after the next line that contains
pattern abc
- ?abc -previous line that contains pattern abc
- g/abc -all lines that contain pattern abc
- v/abc -all lines that do not contain pattern abc
ed also includes a substitution facility, with
the syntax:
begin_line/end_lines/old_text/new_text/command
where command can be g, l, n, p, or gp.
vi
The vi(1) editor allows you to view and edit
a screen-full of text. Text is inserted at the location of the cursor.
vi depends on the block-mode definition of your terminal established
in the terminfo files and set with the $TERM environmental
variable; be sure this is set up correctly before attempting to run
vi.
To begin a vi editing session, enter a "vi
filename" command at the shell. For a new file, vi
will return an empty screen with tilde characters (~) in the left
column of each line; for an existing file, vi will display
the first screen of the file. Like ed(1), vi has an
append mode and an edit mode.
There are more than 100 commands within vi; the
following lists identify a basic set. vi uses "control
characters" for a number of functions; these are denoted using
the ^ character. For instance, "control D" (^d) is
typed by holding the CTRL key down and pressing the D key.
- a -add text after cursor
- i -insert text before cursor
- o -insert line below cursor and begin inserting text
- O -insert line above cursor and begin inserting text
ESC -(ESCAPE key) leave append mode and return
to edit mode
- ZZ -write file to disk and quit vi
- ^f -move forward a full screen
- ^d -move forward a half screen
- ^b -move backward a full screen
- ^u -move backward a half screen
- j -move down one line in same column (edit mode)
- k -move up one line in same column (edit mode)
- l -(also space bar) move one character to right (edit
mode)
- h -(also backspace key) move one character to left (edit
mode)
- G -move to beginning of last line
- H -move to beginning of first line of screen
- M -move to beginning of middle line of screen
- L -move to beginning of last line of screen
- dw -delete current word (edit mode)
- ^w -delete current word (append mode)
- dd -delete current line (edit mode)
- cw -replace current word
- x -delete current character (edit mode)
- r -replace current character
- cc -replace all characters in current line
- D -delete remaining characters in the current line (edit
mode)
- C -replace remaining characters in the current line
- . -repeat previous command
- u -undo previous command
The search and replace functionality of ed can
be accessed through the ex(1) editor, executed by entering
":" from edit mode.
sed
sed(1) is a stream-oriented version of ed(1).
It applies a list of editor commands to each line in one or more files,
writing the resulting modified lines to standard output (or redirected
to a file). The lines to be edited can be selected by regular expressions.
sed is a convenient tool for removing unwanted
fields, transforming all occurrences of one string to another string,
or adding a new field to each line. As a very simple example,
the following shell script replaces every occurrence of the string
"cat" with "dog":
sed 's/cat/dog/g' filename
You can create a file that includes the sed specifications,
then identify that file on the sed command line. For instance,
if you create a file called addblank that contains the following:
a
^D
then issue the following command:
sed -f addblank filename
a blank line is inserted after every line in filename.
sed is most commonly used in scripts to edit
existing files on the system. For instance, if an add-on package requires
that lines be added to the /etc/profile file or /dev/README,
the script can use sed to add lines at the end. Whatever is in the
file will be left as is, and the required information is added at
the end. See the sed manual page or a general UNIX system text
for more information and instructions on using sed.
Filters
A number of REAL/IX Operating System utilities are classified
as filters. A filter reads its standard input, transforms the data
in some way, and writes the result to its standard output. Filters
are commonly used together, with the output from one piped to the
next:
filter1 < input-file | filter2 | filter3 > output-file
Bytes flow from the input file to the output file through
the pipe. Each filter performs a rather small, specialized function:
the first filter might translate certain characters, the second filter
might rearrange the lines (typically by sorting), and the third might
eliminate duplicate lines. By using several filters together, they
perform a more complex function.
The following sections give an overview of some of the
more common filters.
grep
grep(1) selects lines from a file, based on matching
a pattern (or regular expression, as discussed in Metacharacters,
Chapter 7). The pattern is commonly just a simple string. For example,
to search the current directory for all references to fcntl(2),
the command is:
Useful options to grep can select lines that
do not match the pattern, can print the number of each matching line,
and can make a lowercase pattern match an uppercase pattern as well.
By using grep with regular expressions, you can specify complex
matching criteria, such as "lines that begin or end with the
specified pattern," "lines containing pattern1 followed
by pattern2," or "a line that contains the nth occurrence
of the specified pattern."
fgrep(1) and egrep(1) are similar to grep.
fgrep can search for multiple patterns in parallel, but can
only search for fixed strings, not regular expressions. egrep
is faster than grep under some circumstances and generalizes
the notion of regular expression. egrep can, for example, extract
lines containing any of several alternate regular expressions; in
other words, the logical OR of several regular expressions.
awk
awk(1) is a pattern matching programming language
whose syntax is modeled after C; it is often used as a report generator.
It is named for its Bell Laboratories authors, Aho, Weinberger, and
Kernighan. Like grep(1), awk selects lines from its
standard input according to specified criteria that are applied in
a single pass over the input stream. awk can then perform actions
on the data it selects.
The action statements operate on fields (by default,
delimited with spaces in tabs) in the selected line and on variables
you declare. Actions include arithmetic, conditional tests, and string
processing. Fields, modified fields, constants, and variables can
be written to the standard output. Special actions, such as writing
totals, can be taken at the beginning and end of the output stream.
sort
sort(1) sorts the lines in a file. The lines
can contain any ASCII characters. Options to sort permit sorting
on multiple fields (delimited by blanks, semicolons, slashes, or other
characters), on specific bytes within fields, into ascending or descending
order, ignoring case or "white space" (blanks and tabs),
and so on. sort can also merge sorted files, optionally eliminating
duplicate lines.
Communication
The REAL/IX Operating System supports the UNIX System
V utilities for sending and receiving mail and files.
Sending Mail
Two commands are available for sending mail: mail(1)
is the simplest, mailx(1) is a more sophisticated electronic
mail facility. The two are compatible: mail sent with mailx
can be received with mail and vice versa.
To send mail with the mail command, do the following:
mail person1 [person2 person3 ...] <CR>
insert lines of message <CR>
and more lines of message <CR>
.<CR>
The message is terminated with a . or, optionally,
a ^D character. mail can also take a file as input using
the shell redirect character:
mailx is a more sophisticated electronic mail
facility. The system prompts you for a Subject which is displayed
when the recipient uses mailx to read mail. In addition, you
can define an alias of several users to streamline sending mail to
groups and escape to an editor while sending mail
To send mail with the mailx command, do the following:
mailx person1 [or alias or list of people] <CR>
The system will prompt you for a Subject:; after
you enter that, you can type your message as for mail; terminate
the input with a ^D character. To escape to an editor while entering
the message, type ~V (vi(1)) or ~e (ed(1)) at the beginning of a line.
To define aliases and do other mailx customization,
set up a .mailrc file in your home directory, for instance:
set askcc append metoo crt=22
set record=$HOME/mail/outbox MBOX=$HOME/mail/mbox
set sign=Joe Smith, Manager of Software Systems
group myfolks bob mary jim sue
The "set record" line establishes the path
name for incoming and outgoing mail (mailx automatically archives
a copy of all outgoing mail. The "set sign" line creates
a standard signature that can be called with ~a (autograph). The "group"
line establishes an alias called "myfolks"; the mailx myfolks
command is then equivalent to mailx bob mary jim sue. The mailx(1)
manual page gives a full list of options that can be set in the .mailrc
file.
Receiving Mail
The mail(1) and mailx(1) commands without
names are also used to receive mail. mail will display all
messages in your mailbox (/usr/mail/name); with the -r
option, messages are displayed in the order they were posted; otherwise
the most recently posted is displayed first.
After each message, the system gives you a ?
prompt. Your response determines what happens to the message, such
as
- n -go to next message; leave this one in mailbox
- p -print this message again
- s file -save in file; default is $HOME/mbox
- d -delete message
- x -exit mail; leave all messages in mailbox
Entering mailx with no names displays a listing of all
messages in your mailbox including any Subject headers posted with
the message. Each message has a number used to identify the message;
this number is used with a command. The following list of commands
all address message #2 in the mailbox:
- p2 -print message
- d2 -delete message
- m2 -mail message
- s2 -save message in file denoted by MBOX in .mailrc file
Console Management
Proper console management can allow you to interact
with more than one process per terminal. conman(1) is the REAL/IX
utility to assist you with console management.
conman
conman(1) allows a user to interact with more
than one shell or terminal session from a single terminal. The user
controls these shells or sessions, known as layers, using various
commands. The current layer is the layer which can receive input from
or send output to the terminal. Other layers attempting to read from
and write to the terminal are blocked. When the output of a non-current
layer is important and should be viewed immediately, the alarm option
can be set; if the current layer is not so enabled, the alarm layer
will automatically become the current layer when it has pending output
for the screen. Access between layers is controlled by entering ^z
(the CTRL-z character); in the current implementation, only this character
can be used as the switch character. A layer is bound to a pseudo
tty device and is manipulated like a real tty device using stty(1)
and ioctl(2). For more detailed information about conman
and its options and commands, refer to the conman manual pages.
Go to Chapter 9 TOC