🌐 Linux/Unix: Networking & Communication
Estimated reading: 3 minutes 23 views

πŸ’¬ Linux/Unix: Messaging Commands – write, wall, mail Explained with Output & Examples

🧲 Introduction – Why Learn Messaging Commands in Linux?

In multi-user Linux/Unix environments, messaging between logged-in users or sending system-wide announcements is crucialβ€”especially on servers and remote systems. Tools like write, wall, and mail allow communication right from the terminal without requiring external apps.

🎯 In this guide, you’ll learn:

  • How to send private messages to another terminal user with write
  • How to broadcast messages to all users with wall
  • How to send and read system email with mail
  • Real examples and expected outputs

πŸ“¨ 1. write – Send a Message to Another Logged-In User

βœ… What is write?

The write command sends a direct message to another logged-in user’s terminal session.

πŸ› οΈ Syntax:

write [username] [tty]

πŸ”Ή How to Use:

  1. Find active users and terminals: who πŸ“€ Output: alice pts/0 2025-06-15 09:12 bob pts/1 2025-06-15 09:14
  2. Write a message: write bob pts/1 Then type your message. To finish, press Ctrl+D.

πŸ“€ Receiver (bob) sees:

Message from alice@hostname on pts/0 at 09:20 ...
Hey Bob! Please check your email. Thanks.

🧠 If you skip tty, it goes to the user’s first active session.


πŸ“’ 2. wall – Broadcast Message to All Logged-In Users

βœ… What is wall?

wall (write all) broadcasts a system-wide message to all logged-in terminals.

πŸ› οΈ Syntax:

wall [file]

Or enter interactive mode:

wall
[Type message here, end with Ctrl+D]

πŸ§ͺ Example:

wall <<EOF
⚠️ System maintenance at 11:00 PM.
Please save your work.
EOF

πŸ“€ Output on all terminals:

Broadcast message from root@server (pts/0) at 21:45 ...
⚠️ System maintenance at 11:00 PM.
Please save your work.

🧠 Requires write permissions enabled on terminals (mesg y).


πŸ“¬ 3. mail – Send & Read System Email

βœ… What is mail?

mail sends and reads messages via the local mail systemβ€”often used for automated alerts or system notifications.

πŸ› οΈ Syntax:

mail [user]

πŸ§ͺ Example 1: Send a message to a user

echo "Backup completed successfully." | mail -s "Backup Report" bob

πŸ§ͺ Example 2: Check your inbox

mail

πŸ“€ Output:

Heirloom Mail version 12.5.  Type ? for help.
"/var/mail/alice": 1 message 1 new
>N  1 bob      Mon Jun 15 10:05  16/512  "Backup Report"

πŸ“¬ Inside mail:

  • 1 – View message
  • d – Delete message
  • q – Quit mail client

πŸ“¦ To install:

sudo apt install mailutils  # Debian/Ubuntu
sudo yum install mailx      # RHEL/CentOS

🧠 Messaging Tools Comparison

ToolPurposeTargetsInteractiveCommon Usage
writeSend message to one userSpecific TTYβœ…User-to-user chat
wallBroadcast to all usersAll TTYsβœ…Maintenance alerts, announcements
mailSend/read system emailUser’s inbox❌ (shell)System logs, job alerts, cron output

πŸ“Œ Summary – Recap & Next Steps

Messaging commands help Linux users and admins communicate instantly, alert others, and manage system notificationsβ€”especially in remote or multi-user server environments.

πŸ” Key Takeaways:

  • Use write to chat with individual users in real time.
  • Use wall to send announcements to all active users.
  • Use mail to send/read system messages, especially in automation.

❓ FAQs

❓ How do I prevent messages from appearing in my terminal?
βœ… Run:

mesg n

❓ How do I allow messages again?
βœ… Use:

mesg y

❓ Where are mail messages stored?
βœ… Usually in /var/mail/<username> or /var/spool/mail/<username>.

❓ Can mail send emails to external addresses?
βœ… Yes, but you must configure Sendmail or Postfix.

❓ What’s the difference between wall and write?
βœ… write is one-on-one, wall sends to all logged-in users.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

πŸ”΅ Linux/Unix: Messaging (write, wall, mail)

Or Copy Link

CONTENTS
Scroll to Top