write (Unix)
The write
command is a Unix utility used for direct, real-time communication between users logged into the same system. It allows one user to send messages directly to another user's terminal.
Functionality:
The write
command essentially copies lines from the user's standard input to the terminal of the specified recipient user. This means the sender's messages appear immediately on the recipient's screen. This continues until the sender terminates the session, typically by pressing Ctrl-D (end-of-file). The recipient will then see "EOF" displayed on their screen.
Usage:
The basic syntax is:
write <user> [tty]
<user>
: The username of the user to whom the message is to be sent.[tty]
: (Optional) The specific terminal device the user is logged into. This is useful if a user is logged in multiple times (e.g., on different virtual consoles or terminal windows). If omitted,write
attempts to send the message to the first terminal the user logged into.
Important Considerations:
- Permissions: For
write
to work, the recipient user must have enabled message reception on their terminal. This is usually controlled by themesg
command. If a user has disabled message reception (usingmesg n
), thewrite
command will fail with a "Permission denied" error. - Interruption: The recipient can interrupt the message stream from the sender using standard terminal interrupt signals (typically Ctrl-C).
- Conversation Protocol: There is no built-in protocol or structure to a
write
session. Users typically establish their own conventions, such as indicating the end of a turn in the conversation with "o" (over) or "oo" (over and out). However, this is merely a social convention, not enforced by thewrite
utility itself. - Alternatives: While
write
provides a simple way to communicate, more modern and sophisticated communication tools liketalk
or instant messaging applications are typically preferred for interactive communication. - Security:
write
should not be used to transmit sensitive information, as the communication is not encrypted and can potentially be observed by other users with sufficient privileges on the system.