Linux provides users with tools to communicate with each other. Some can send messages to a specified user; some can send a group of messages; some can even send content as an email to a user’s inbox list.

Send Message to a Specific User

Before we send information to a user, we first need to know which terminal the message receiver is at:

1
who
img

Check logged in users

When we know the terminal of the message receiver, we can send some messages to the terminal:

1
2
3
4
5
write user pts/1    # Run this command first
Hi Mate,
This is a msg from root.
Root
# Press Ctrl + D at this line
img

Sending message to a user called user

When the message is sent, the receiving terminal should print out the content just sent out by the root terminal:

img

Sending message to a user called user

Disable or Enable Messaging Function

We can use the mesg command to turn on or off the ability to send and receive messages.

Here are two arguments for mesg command:

Option Meaning
n Disable send and receive functions. This parameter is not valid for messages sent from root.
y Enable send and receive functions.

We can set root to not receive or send messages:

1
mesg n
img

Disable the send and receive functions

When a user attempts to send a message to root, the system displays that root has disabled the messaging feature:

1
write root pts/0
img

The user attempts to send a message to a root user who has turned off the messaging function

Group Messaging Function

We can use the wall command to broadcast messages to all users:

1
wall
img

Send information to all users, including the sender of the message

When the message is broadcasted, the receiving terminals should print out the content just sent out by the root terminal:

img

Broadcasting message to all users

Output the Message Without the Banner

With the -h option, the message sent does not display the sending host:

1
wall -n
img

Send information to all users without the banner, including the sender of the message

When the message is broadcasted, the receiving terminals should print out the content just sent out by the root terminal without the banner:

img

Broadcasting message to all users without the banner

Send an Email to a User

We can send mail to users based on mail, but we first need to install the mailx package:

1
yum mailx -y

We can try sending an email to root:

1
2
3
4
5
6
mail -s 'Hi root' root
Hi Mate,
This is an email from user.
Talk soon.
User
.    # This is act as an terminate symbol
img

Send an email to root

The root user’s terminal should prompt a message:

img

Received an email

We can view the newly received mail through the mail command:

1
mail
img

Viewing the received email

When we have finished checking the e-mail, we can terminate the program by pressing the Ctrl + D key combination.

References WRITE(1), MESG(1), WALL(1), GNU Mailutils

Buy me a coffeeBuy me a coffee