Communication Notification and Sharing Commands

 

Primary Command for Communication to Another Logged-In User

The write command in Linux is used to send a message directly to another logged-in user, which appears at the bottom of their terminal session.


🔹 write Command – Overview

📌 Syntax:

write <username> [tty]


📌 Example:

write prakash pts/2

Hello, your deployment is failing due to config.yaml.

(Press Ctrl+D to end)


If the recipient is logged into more than one terminal (like pts/0, pts/2), specify the correct one. You can check this using:

who


📌 How it Works:

  • It sends a message line-by-line in real-time.

  • Message appears at bottom of the recipient’s screen, interrupting whatever is happening.

  • Use Ctrl+D to end the message.


🔹 Similar Commands and Concepts

Command

Purpose

Use Case

wall

Write message to all users

System-wide broadcast (e.g., “System going down for maintenance at 10PM”)

talk

Real-time conversation between two users

Two-way chat over terminals

mesg

Allows or disallows receiving messages

mesg n to block, mesg y to allow

mail

Send and receive user emails locally

Sending system alerts/reports to users

notify-send

Desktop notification (GUI)

Notifies GUI users in real-time

ssh + write

Remote communication

Write messages across SSH sessions

screen/tmux + chat

Shared terminal session

Pair programming or real-time support

/dev/pts/*

TTY communication

Echo directly to user terminals


🔹 Real-world Use Cases

  1. System Admin Alerts:

    • Notify logged-in users before reboot using wall.

  2. Team Collaboration on Same Host:

    • Use write or talk to chat when using the same system.

  3. Education or Training:

    • Teacher sends instruction to student terminals in labs.

  4. Instant Alerts in Terminal:

    • Automate alert via write to notify a user if a script fails.

  5. Interactive Terminal Chat:

    • talk can allow back-and-forth chatting.

  6. Security Monitoring:

    • Admin warns users on suspicious activity in real-time.


🔥 FAANG-Level 20 Questions & Answers


🔹 Conceptual & Practical Questions

  1. Q: What’s the difference between write and wall?
    A: write is for one-to-one messaging; wall broadcasts to all logged-in users.

  2. Q: How does mesg affect write?
    A: If the recipient has disabled messages via mesg n, write won’t work.

  3. Q: How do you find a user’s terminal to send a message?
    A: Use who to see usernames and their terminal (e.g., pts/0).

  4. Q: How do you broadcast a message to all users except root?
    A: Use wall and set mesg permissions to disallow for root.

  5. Q: Can write be used across different machines?
    A: Not directly. Use SSH + write or other tools like talk over network.

  6. Q: What happens if the recipient is in a full-screen app (e.g., vim)?
    A: Message may disrupt the screen or appear after exiting the editor.

  7. Q: Can I send rich text or emojis using write?
    A: No. It only supports plain ASCII text.

  8. Q: How do I block incoming terminal messages?
    A: Use mesg n.

  9. Q: How do you script alerts to be sent via write?
    A: echo "Error in backup script" | write prakash pts/0

  10. Q: Can write be logged?
    A: Not by default. You must enable shell logging or audit logs.


🔹 Security, Edge Cases & Advanced

  1. Q: How to restrict write command use system-wide?
    A: Modify /etc/security/limits.conf or use ACLs.

  2. Q: What vulnerabilities can write introduce?
    A: Message injection or session spoofing if not restricted.

  3. Q: How to prevent wall or write from spamming terminals?
    A: Use mesg n, or restrict access to trusted users.

  4. Q: What’s a real-world scenario where talk is better than write?
    A: When real-time bi-directional chat is needed during troubleshooting.

  5. Q: How do you automate a critical alert to all devs during a prod outage?
    A: echo "ALERT: DB down" | wall

Q: Can write be integrated with shell scripts for alerts?
A: Yes. Example:

if ! ping -c 1 8.8.8.8; then

  echo "Network Down!" | write prakash pts/2

fi


  1. Q: Can you write directly to a terminal without write?
    A: Yes, e.g., echo "msg" > /dev/pts/2

  2. Q: What are /dev/pts/N files?
    A: Pseudo-terminal slave devices representing user sessions.

  3. Q: How to send alert only to users in a specific group?
    A: Loop over who output, check group using id command, then write.

  4. Q: Compare write, wall, and talk in terms of UX and scalability.
    A:

    • write: manual, one-to-one.

    • wall: simple broadcast.

    • talk: real-time two-way communication.


✅ Summary Table

Command

One-to-One

Broadcast

Real-Time

GUI Notification

Requires TTY

Two-Way

write

✅ (line-by-line)

wall

talk

✅ (interactive)

mesg

mail

✅ (via alias)

notify-send


Would you like a hands-on lab-style guide to simulate a real-time write/wall session or a visual workflow of communication in terminals?


Distributed by Gooyaabi Templates | Designed by OddThemes