[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Commands Reference, Volume 6

write Command


Opens a line of communication to send messages to other users on the system in real time.


To Query All Messages Awaiting Replies From Users on a Host and Display them with their Handles

write -q [ -n Host ]

To Reply to a Message Sent by a Utility or a Shell Script, or Redisplay the Message Associated with a Given handle

write -hHandle, { ok | cancel | query } [ -n Host ]

To Send Messages to a User, Optionally on Another Host or a Particular Device

write [ -r  ] { [ -n HostUser | User@Host  } [  Line ]


The write command enables message sending over the system in real time. It provides conversation-like communication with another logged-in user. Each user alternately sends and receives short messages from the other workstation. Long messages can be sent by putting the complete message in a file and then redirecting that file as input to the write command.

For another user (as specified by the User parameter) to receive a message, that user must be logged in and must not have refused message permission. When a message is sent to a user who is not logged in, the message user not logged in appears. If the message is sent to a user who has refused message permission by setting the mesg command to no, the message write: permission denied appears.

When the write command is issued, it immediately sends the following message, along with an attention-getting sound (the ASCII BEL character) to the message recipient or target:

Message from SenderID on SenderHostname (ttynn) [Date] ... 

With a successful connection, the write command sends two ASCII BEL characters to both workstations. The beep alerts the sender that the message can begin and it alerts the receiving user that a message is coming.

Sending occurs one line at a time as the Enter key is pressed. The communication link from the sender to the receiver remains open and sending continues until the Ctrl-D key sequence ends the sending link. Then an end-of-text character (<EOT>) is sent to the target workstation and the write command mode is terminated.

The receiving or target user can respond by sending a write command to the originating user. This opens a line of communication from the receiver back to the sender, enabling message responses in return. For this type of exchange, the following convention is useful: When you first write to others, wait for a response before sending any text. End a message with a signal such as o (over) to alert the other person to reply. Use oo (over and out) when the conversation is finished.

If the character ! (exclamation point) is found at the beginning of a line, the write command calls the shell to execute the rest of the line as a command. For example, while waiting for a response, precede the operating system li command with an ! (!li) and the directory list appears on your workstation. Typing the li command without the preceding ! is interpreted by the system as text to be sent to the target user.

When you write to a user who is logged in at more than one workstation or multi-using more than one process, the write command uses the first login instance found in the /etc/utmp file as the message delivery point (usually the login or console shell), and you get the message:

UserID is logged on more than one place.
You are connected to "Workstation".
Other locations are:

When this message is received, if you wish to send the message to a location other than the initial login location, the target user can be contacted at a different location by specifying the Line of the location (tty00, for example).

Permission to write to another user is granted or denied by the individual user with the mesg command. Some commands deny message permission while they are running to prevent interference with their output. A user with root user authority can write to any workstation regardless of the workstation's message permission.

You can use the write command to converse with users on other hosts. You can identify a user on a remote host by using the -nHostName flag or the User@Host parameter. In order to write to a user on a remote host, the writesrv daemon must be running on both the current host and the remote host.

The write command is also used by the qdaemon daemon to send messages to users on other hosts and to wait for replies. There are only three valid replies:

ok The original write exits with a status of 0.
cancel The original write exits with a status of 1.
query The message associated with the given handle is displayed.


User Specifies the user ID of the person to receive the message text.
User@Host Specifies the user ID and remote host of the person to receive the message text.
Line Contacts the target user at another location (tty00 , for example).


-h Handle,Reply Replies to a message sent by a utility or shell script using write with the reply option. The value to be used for the Handle variable is generated internally and supplied to the user in the text of the original message. The reply can be ok , cancel , or query .
-nHost Specifies a remote host. The Host variable may be a nickname or an internet address.
-q Queries all messages awaiting replies from users on a host and displays them with their handles.
-r Generates a message handle, places it in the message header, sends the message, and waits for a reply. This flag is used by the qdaemon daemon for operator messages and can be put in shell scripts. It is not used for interactive conversations. An exit status of 0 indicates that the reply was ok , a status of 1 indicates that the reply was cancel , and an exit status of 2 indicates that the user could not be contacted.
  1. The writesrv daemon must be running on the target host in order for any of the flags to work. If you are not using either the -n flag or @Host, but using -h, -q, or -r, the writesrv daemon must be running on your host.
  2. If TCP/IP is not installed on your machine but the HostName is set, in order to converse with users on the local host using the write command with the -h, -q, or -r flag, you must append your host name to the end of the loopback entry in the /etc/hosts file. The original entry should read: loopback LocalHostName
    The new entry should read: loopback LocalHostName HostName

Exit Status

This command returns the following exit values:

0 Successful completion.
>0 The addressed user either is not logged on or denies permission.


  1. To write a message to a user who is logged in, enter:
    write june
    Press the Enter key and type,
    I need to see you! Meet me in the computer room at 12:30.
    Then press the Ctrl-D key sequence to terminate the write command mode.

    If your user ID is karen and you are using workstation tty3 , june 's workstation displays:

    Message from karen on trek tty3 Aug 17 11:55:24  ...
    I need to see you!  Meet me in the computer room at 12:30.
  2. To hold a conversation, enter:
    write june
    Press the Enter key and type,
    Meet me in the computer room at 12:30.
    This starts the conversation. The o at the beginning of the next line means the message is over. It tells June that you are waiting for a response. Do not press Ctrl-D if you wish to continue.

    Now June replies by typing:

    write karen
    Presses the Enter key and types,
    I'm running tests at 12:30. Can we meet at 3?
    And you might respond:
    OK--the computer room at 3.
    The oo means over and out, telling June that you have nothing more to say. If June is also finished oo , then you both press Ctrl-D to end the conversation.
  3. To write someone a prepared message, enter:
    write june < message.text
    This writes the contents of the message.text file to june 's workstation.
  4. To write to the person using a certain workstation, enter:
    write -n console
    Press the Enter key and type,
    The printer in building 998 has jammed.
    Please send help.
    Then press the Ctrl-D key sequence.

    This writes the message to the person logged in at the workstation /dev/console .

  5. To send a message to user spuds at host partya , enter:
    write -n partya spuds
    Press the Enter key and type,
    Your new tape has just arrived,
    come see me to pick it up.
    Then press the Ctrl-D key sequence.


    write spuds@partya
    Press the Enter key and type,
    Your new tape has just arrived,
    come see me to pick it up.
    Then press the Ctrl-D key sequence.
  6. Here is an example of a message sent by the qdaemon daemon:
    Message from mary on trek (tty10) Aug 17 10:03:34 ...
    Use "write -h 6398492,reply" to reply
    Please insert tape number 5 into rmt0.
    To reply in the affirmative, enter:
    write -h 6398492,ok
    Then press the Ctrl-D key sequence.

    To reply in the negative, enter:

    write -h 6398492,cancel
    Then press the Ctrl-D key sequence.

    With the -h flag, there is no need to supply the host name or user ID. This information is tracked with the handle.


                          Contains TCP/IP host information.
                          Contains user and accounting information for the who, write, and login commands.

Related Information

The mesg command, wall command, who command, writesrv command.

Shells Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.

[ Previous | Next | Contents | Glossary | Home | Search ]