How to send messages or chat in Linux

There are plenty of rich programs available in Linux that offer chat over the network. However, if you need a basic program or tool that allows communication between logged-in users on the system, you do not need to install additional programs or third-party tools. Linux includes two commands for internal communication. These commands are the write and wall. The write command allows us to send messages and chat in real-time with another user on the system. The wall command lets us send messages to all users simultaneously.

How the write and the wall commands work

Linux is a multi-user system. It allows several users to log in and work simultaneously. It uses sessions to keep a user’s activity separate from other users. When a user logs in, it assigns a new session to that user and uses this session to track, log, and monitor his activities.

The write command and the wall command use a simple mechanism. Both commands take the message from one session and deliver it to another. The difference between both commands is that the write command gives a message to one session while the wall command delivers it to all sessions.

The following image shows how the write command delivers the messages.

write command example

The following image shows how the wall command delivers the messages.

wall command example

Key points

  • Both commands are Shell inbuilt and do not require additional configuration or setup before use.
  • Both commands only send messages. To reply to a received message, the user must use the same command again.
  • Both commands deliver messages only between the active users. You can not use these commands to send messages to logged-off users.
  • Both commands use Shell sessions to deliver the messages. You can not use these commands to deliver the messages to a network user or a user outside the system.

Examples of the write and wall commands

Create a few user accounts and log in from these accounts. Use virtual consoles to log in simultaneously.

multiple users login

Sending a message to all users

The wall (Write All) command sends a message to logged-in users. The usage of the wall command is simple. Type wall at the command prompt and write the message. You can use any symbol, character, or white space in the message. You can append the message in multiple lines. After typing a message, press the ctrl+d to send it to all users.

sending message to all users

Chatting at the command prompt

The write command sends messages to an individual user. It requires the username of the recipient as the argument. For example, if the user c wants to send a message to user a, he will use the following command.

[c@localhost ~]$write a

The above command starts a chat session that captures information typed line-by-line at the command prompt by user c and delivers it to the command prompt of user a. No matter what user a is doing, if his session is active, it displays the message on his terminal. To dismiss the received message, he has to press the Enter key. If the user a wants to reply, he has to start his chat session by typing the following command.

[a@localhost ~]$write c

The ctrl+c keys combination terminates the chat session. We can divide this process into the following three steps:

  1. Initiating/starting the chat
  2. Chatting
  3. Terminating/ending the chat

Let’s understand the above process with an example.

Initiating/starting the chat

Since the write command allows communication only between logged-in users, user c executes the who command to view a list of logged-in users. It prints the list of all logged-in users. From the output, user c confirms user a has an active session.

User c types write at the command prompt and hit the Enter key. It brings the chat prompt. User c types his message and hits the Enter key. The write command grabs the typed message and sends it to the command prompt of user a. As mentioned above, the write command only delivers the messages. It does not accept the reply to messages. So, if the user wants to reply, it has to open its chat session separately.

User a dismisses the received message by pressing the Enter key, types write c at the command prompt, and hits the Enter key to start its chat session.

Chatting

After starting the chat session from both ends, they can exchange messages. To send a message in the active chat session, they only need to hit the Enter key.

Terminating/ ending the chat

After completing the chat, they can terminate it by pressing the ctrl+c keys. The following image shows the above example.

chat in linux at command prompt

Stopping/controlling the chat or messages

Since the write command delivers messages without any prior notification interrupting the running tasks, sometimes it becomes very annoying. For example, a user is editing a critical configuration file and receives a useless message from another user just in the middle of editing. It can generate errors in the configuration file. Luckily, the write command allows us to control the incoming messages.

The mesg command lets us control the incoming messages. It supports two options: n and y. The n option turns off the incoming messages. The y option turns them on.

The following image shows how to use the mesg command to enable/disable incoming messages.

stop receiving messages linux command prompt

Conclusion

The wall and write commands allow users to communicate on a standalone Linux system. In this tutorial, I explained how to use these commands to send and receive messages.

ComputerNetworkingNotes Linux Tutorials How to send messages or chat in Linux

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com