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
🔹 Real-world Use Cases
System Admin Alerts:
Notify logged-in users before reboot using wall.
Team Collaboration on Same Host:
Use write or talk to chat when using the same system.
Education or Training:
Teacher sends instruction to student terminals in labs.
Instant Alerts in Terminal:
Automate alert via write to notify a user if a script fails.
Interactive Terminal Chat:
talk can allow back-and-forth chatting.
Security Monitoring:
Admin warns users on suspicious activity in real-time.
🔥 FAANG-Level 20 Questions & Answers
🔹 Conceptual & Practical Questions
Q: What’s the difference between write and wall?
A: write is for one-to-one messaging; wall broadcasts to all logged-in users.Q: How does mesg affect write?
A: If the recipient has disabled messages via mesg n, write won’t work.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).Q: How do you broadcast a message to all users except root?
A: Use wall and set mesg permissions to disallow for root.Q: Can write be used across different machines?
A: Not directly. Use SSH + write or other tools like talk over network.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.Q: Can I send rich text or emojis using write?
A: No. It only supports plain ASCII text.Q: How do I block incoming terminal messages?
A: Use mesg n.Q: How do you script alerts to be sent via write?
A: echo "Error in backup script" | write prakash pts/0Q: Can write be logged?
A: Not by default. You must enable shell logging or audit logs.
🔹 Security, Edge Cases & Advanced
Q: How to restrict write command use system-wide?
A: Modify /etc/security/limits.conf or use ACLs.Q: What vulnerabilities can write introduce?
A: Message injection or session spoofing if not restricted.Q: How to prevent wall or write from spamming terminals?
A: Use mesg n, or restrict access to trusted users.Q: What’s a real-world scenario where talk is better than write?
A: When real-time bi-directional chat is needed during troubleshooting.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
Q: Can you write directly to a terminal without write?
A: Yes, e.g., echo "msg" > /dev/pts/2Q: What are /dev/pts/N files?
A: Pseudo-terminal slave devices representing user sessions.Q: How to send alert only to users in a specific group?
A: Loop over who output, check group using id command, then write.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
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?