First we will discuss the topics left over from Chapter 8. Then, Chapter 9 discusses methods of communicating in UNIX. The objectives important to this chapter are:
Chapter 8We left off with the tee command in Chapter 8, which takes us next to the grep command. grep was discussed in the Chapter 8 notes, but as a recap, it is a search program that is used to find patterns of text in text files. To search for a pattern that contains more that one word, enclose the phrase to search for (called a regular expression) in quotes. Several options for grep are useful:
The sort command sorts text files. So far, so good. It has several
options, several of which are necessary from time to time. The syntax
of the command is:
sort -options file_to_sort file_to_write
As usual, the options are not required. Neither is the file_to_write. It is only used with the -o option, when you do not wish the output to come to the screen, the default destination. Obviously, we could use a pipe and tee to send output both places. The default sort order is ASCII order. Options that override this are:
The user profile is the file that contains individual settings for a user. It must be located in the user's home directory, and must be called .profile in order to be read by UNIX. The user is allowed to edit this file, by default, as well as the .exrc file that affects how vi works for that user, and the .mail file that affects how the mail system works for that user.
The export command is used with variables. One reason shells are called shells, is that you can have several running at one time, layered inside one another. When you start a new shell inside the current shell, the new one does not know anything about any shell variables set in the first one, unless those variables are marked with the export command.
Chapter 9The first advice our author give us in this chapter is to be polite, send only messages that need to be sent, and save a copy of all messages. These three precautions will save you embarrassment, save your users anger and irritation, and save you time later.
It is possible to send messages several ways in UNIX. To send a message directly to another user who
is logged on, enter the command:
This starts a process that will write text to the other user's screen. Every line you enter will be sent to the other user, until you press ctrl-d to end the process. The other user can initiate a write command to reply to you, even while yours is still going on. This could be done immediately to notify the sender that you do not want to talk now.
If you don't want to be interrupted at all by messages, you can use the mesg command the letter n as an argument (mesg n) to turn off message reception. Using y as an argument will turn message reception back on.
The news command will read and display files that are placed in the /usr/news directory. This is
another way for system operators to communicate information to you, and for users to communicate
lengthy messages to all people who might want to read them. Options allow the user to specify what
The wall command means to write all, or to use the write command to all current users on the system. This command is very intrusive by nature and should not be used for trivial messages. It is immediate, and like write, it breaks into a user's current session. The command has some limitations. It will not be received by users who have message reception turned off. Also, it may not be accessible by anyone but the system administrator. If the idea of irritating all users does not bother you, you should know that the message is still tagged with your user name.
A more flexible and useful messaging process is e-mail, or electronic mail. E-mail can be sent to any number of users, it is not intrusive and the user need not be logged on at the time it is sent in order to see it later. While most environments now use third-party e-mail systems, you should be aware that there are e-mail functions built into UNIX.
Depending on the system you use, either the mail or the mailx command may be available to you. Our author discussed mailx.
To use either e-mail command, you must have a mailbox on the system. This is a file that will hold your e-mail messages. This is your system mailbox. You can read mail in it with the mailx command, which will put a copy of that mail in a file called mbox, unless you save it elsewhere or exit mailx with the x command.
Like a lot of UNIX, you can save customized settings for your e-mail environment. mailx will look for these settings in a file called .mailrc in your home directory. This will override the general settings found in the mail.rc file.
Like using write, you can begin the mailx command by typing:
This will begin a process that expects you to type a message to the named user. You end the message by entering ctrl-d, as the end of file marker. The message is then transmitted to the user's mail box.
Mail can be read by entering the mailx command with no argument. Your queue of messages will be displayed, and you can read a message by entering the message number displayed for it. When you wish to see the next message, enter its message number. Entering q will quit the mailx program and save messages you have read as noted above. Entering x will quit without saving opened mail to the mbox.
The mailx program has several commands available to the user in the input mode. These are noted in Table 9-3. Just to be different, these commands all start with a tilde. These commands are not mnemonic, and should be practiced to gain familiarity with them. We will do this in class.