write

communicationLinux/Unix
The write command is one of the most frequently used commands in Linux/Unix-like operating systems. write Send a message to another user

Quick Reference

Command Name:

write

Category:

communication

Platform:

Linux/Unix

Basic Usage:

write [options] [arguments]

Common Use Cases

    Syntax

    write user [ttyname]

    Options

    The write command has minimal options compared to many other Linux commands. It primarily takes arguments rather than traditional options with dashes.

    Argument Description
    user The username of the recipient
    ttyname Optional terminal name if the user is logged in on multiple terminals

    Interactive Mode

    After executing the write command, you enter an interactive mode where:

    • Each line you type is sent to the recipient when you press Enter
    • The recipient sees your username, terminal, and timestamp with each message
    • To end the session, press Ctrl+D or Ctrl+C

    Examples

    How to Use These Examples

    The examples below show common ways to use the write command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Send a message to user 'john' write john
    # Send a message to user 'mary' on a specific terminal write mary pts/3
    # Advanced Examples Advanced
    # Send a message from a file
    cat message.txt | write susan
    # Send a multiline message using a here document write david << EOF
    Hello David, This is an important message. Please respond when you get this. EOF # Combine with other commands echo "Meeting in 5 minutes!" | write @all # Send the output of a command to another user date | write robert # Send a message to all users (if supported by your system) wall "System will reboot in 10 minutes"

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `write` command is a traditional Unix/Linux utility that enables real-time text communication between users logged into the same system. It allows sending messages directly to another user's terminal, providing a simple way for system administrators and users to communicate without email or other messaging systems. **Core Functionality:** 1. **Direct Messaging**: write sends text directly to another user's terminal, displaying it immediately if their terminal permissions allow it. 2. **Terminal-to-Terminal Communication**: The command works between different terminal sessions on the same system, allowing users logged in from different locations to communicate. 3. **Interactive or Piped Input**: write can be used interactively (typing messages line by line) or can receive input from pipes or redirections. **Common Use Cases:** 1. **System Administration**: System administrators use write to notify users about impending system events: ``` write all "System maintenance in 15 minutes, please save your work." ``` 2. **User Collaboration**: Users working on shared systems can quickly exchange information without switching to email or chat applications. 3. **Remote Assistance**: Users can request and receive help from administrators or other users while working in terminal sessions. 4. **Emergency Notifications**: Critical system messages can be immediately delivered to active users. **Technical Details:** 1. **Permission System**: The write command respects terminal message permissions set by the `mesg` command: - If a user has executed `mesg n`, they will not receive messages from write - If they've used `mesg y` (the default on most systems), they will receive messages 2. **Terminal Detection**: write needs to know which terminal the recipient is using. If a user is logged in on multiple terminals, you can specify which one with the ttyname argument. 3. **Message Format**: Messages sent by write typically appear on the recipient's terminal with a header showing: - The sender's username - The sender's terminal - The time the message was sent 4. **Interactive Protocol**: When used interactively, write establishes a two-way communication channel. Both users can type messages, with each message appearing on the other's terminal. The convention is to end your part of the conversation with "o" (over) and the entire conversation with "oo" (over and out). **Historical Context:** The write command dates back to early Unix systems in the 1970s, when time-sharing computers had multiple users connected via physical terminals. It was an essential tool for system administrators to communicate with users and for users to communicate with each other. Despite being considered somewhat archaic in the age of instant messaging and email, write remains valuable in server environments, particularly for system notifications and emergency communications. **Comparison with Related Commands:** 1. **wall**: The `wall` (write all) command is similar to write but sends messages to all logged-in users. It's often used for system-wide announcements. 2. **talk**: The `talk` command is an enhanced version of write that splits the screen, allowing for more structured two-way communication. 3. **mesg**: The `mesg` command controls whether other users can write to your terminal (mesg y enables, mesg n disables). 4. **who**: The `who` command with the -T option shows which users have message reception enabled or disabled. **Security and Privacy Considerations:** 1. **Privacy Control**: Users can control whether they receive messages using the mesg command, providing basic privacy control. 2. **No Authentication**: Traditional write provides no authentication beyond Unix usernames, so messages could potentially be spoofed. 3. **No Encryption**: Messages sent via write are not encrypted and could potentially be intercepted if the system is compromised. 4. **Terminal Access Required**: write only works for users currently logged in with terminal access, limiting its utility in environments where users primarily use graphical interfaces. **Best Practices:** 1. **Respect User Preferences**: Check if users have message reception enabled before attempting to write to them: `who -T` shows a '+' for users who accept messages. 2. **Brief and Clear Messages**: Keep write messages concise and clear, especially for system announcements. 3. **Identify Yourself**: When sending messages to users who might not expect communication, start with a clear identification of who you are. 4. **Follow Conventions**: Use conventional signaling like "o" (over) and "oo" (over and out) to indicate message status in interactive sessions. 5. **Terminal Awareness**: Be aware that write messages interrupt whatever the user is doing in their terminal, which can be disruptive if they're in the middle of editing a file or running a command. Despite newer communication technologies, write remains a valuable tool in the system administrator's toolkit, particularly for direct, immediate communication with users in a terminal environment.

    Related Commands

    These commands are frequently used alongside write or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the write command works in different scenarios.

    $ write
    View All Commands