WIPIVERSE

write (Unix)

write is a standard utility found in Unix and Unix-like operating systems used to send messages to another user by writing text directly to that user's terminal (TTY). It is a command-line program that enables real-time, text-based communication between logged-in users on the same machine.

Overview

The write command copies lines entered by one user from their terminal to the terminal of another user. It is part of the suite of standard Unix commands and is specified in the POSIX standard.

History

The write command was included in the First Edition of the Research Unix operating system, released on November 3, 1971, by AT&T Bell Laboratories. The command was developed by Dennis Ritchie and Ken Thompson. A similar messaging concept had previously appeared in the Compatible Time-Sharing System (CTSS). According to the Linux man page, a write command appeared in Version 6 AT&T UNIX.

Syntax and Usage

The general syntax of the command is:

write user [ttyname]
  • user is the name of the target user to whom the message is to be sent.
  • The optional ttyname argument specifies a particular terminal when the target user is logged into more than one terminal. If omitted, write selects a terminal automatically, typically choosing the one with the shortest idle time.

When the command is run, the target user receives a message of the form:

Message from yourname@yourhost on yourtty at hh:mm ...

Any further lines entered by the sender are copied to the specified user's terminal. The session is terminated by sending an end-of-file (EOF) character (often Ctrl+D) or an interrupt character, at which point the recipient sees the message "EOF."

Features and Restrictions

  • Reply mechanism: If the other user wants to reply, they must run write themselves.
  • Blocking unwanted messages: A user can prevent others (other than the superuser) from writing to them using the mesg command.
  • Automatic blocking: Some commands, such as nroff and pr, may automatically disallow writing to avoid overwriting their output.
  • Conversation protocol: The traditional protocol uses the string -o (at the end of a line or on a line by itself) to signal that it is the other person's turn to talk, and oo to indicate that the sender believes the conversation is over.

Sample Usage

A conversation initiated between two users on the same machine:

$ write root pts/7
Hello!

This message appears to the target user on that console as:

Message from root@wiki on pts/8 at 11:19 ...
Hello!

Related Commands

  • mesg – controls whether other users may send messages to the current terminal.
  • talk – a more advanced interactive communication utility.
  • wall – writes a message to all logged-in users.
  • who – lists who is logged in and on which terminals.

Availability

On Linux, the write command is distributed as part of the util-linux package, available from the kernel.org project. It is also part of the POSIX and Single UNIX Specification set of commands and is implemented across various Unix and Unix-like operating systems.

References

  • write(1) – Version 7 Unix Programmer's Manual
  • Unix Programmer's Manual (1st ed.), Bell Labs, 3 November 1971
  • write(1) Linux manual page (man7.org)
  • Wikipedia: Write (Unix)
Browse

More topics to explore

    Browse all articles