Previous Table of Contents Next

Module 88


The external mesg command allows or denies other users the privilege of sending messages to your terminal screen. By using the mesg command you can prevent people from writeing or talking to you while you are logged on the system.


The general format of the mesg command follows.

     mesg [ -n | -y ]


The following list describes the options and their arguments that may be used to control how mesg functions.

-n Prevent other users from sending messages to your terminal.
-y Allow other users to send messages to your terminal.

If no options are given the current message mode is returned.


If you keep getting interrupted by other users, enter

     cj> mesg n
     cj> mesg               # use mesg alone to check current state

and you can continue on in peace. The mesg command only works for the current login session. If you log out and back in, you must reset the mesg mode as desired. The default is to allow other users to send messages to you.

The mesg command prevents other users from writing to your terminal by changing the write permission for others on your /dev/ttyXX terminal port.


Refer to the write and talk commands described in modules 161 and 132, respectively.


All /dev/tty* terminal files are valid for message mode control.

RETURN CODES The mesg command returns the following codes:

0 messages are allowed
1 messages are denied
2 mesg failed with an error


The mesg command is used to control when people can and cannot interrupt your work by writing to your terminal screen. It is automatically turned on when you are in vi. This prevents other users from garbling your edit screen. It is a desirable feature if someone keeps bothering you and you are starting to become annoyed.


In this activity you use the mesg command to deny other users write permission to your terminal, then you set the mesg mode back. Begin at the shell prompt.

1.  Type mesg and press Return to display the current message mode. It should be set to yes.
2.  Type mesg -n and press Return to change the mode to no. Now, if feasible, contact a fellow user and have him/her try to write to you. The person should receive a message stating "Permission denied." Or, you can try to write to your own login.
3.  Type mesg -y and press Return to change the mode back to yes. If you like, have the user try to write you a message now. You should receive each line of the message as the user presses Return at the end of each line.
4.  Turn to Module 132 to continue the learning sequence.

Previous Table of Contents Next