π¬ 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:
- Find active users and terminals:
who
π€ Output:alice pts/0 2025-06-15 09:12 bob pts/1 2025-06-15 09:14
- Write a message:
write bob pts/1
Then type your message. To finish, pressCtrl+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 messaged
β Delete messageq
β Quit mail client
π¦ To install:
sudo apt install mailutils # Debian/Ubuntu
sudo yum install mailx # RHEL/CentOS
π§ Messaging Tools Comparison
Tool | Purpose | Targets | Interactive | Common Usage |
---|---|---|---|---|
write | Send message to one user | Specific TTY | β | User-to-user chat |
wall | Broadcast to all users | All TTYs | β | Maintenance alerts, announcements |
mail | Send/read system email | Userβ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 :