How to Send a Message to Logged Users in Linux Terminal?


If you are using a Linux system, there might be a possibility that you need to communicate with multiple logged-in users for various reasons, such as sending critical messages or notifications. Fortunately, there is a way to send messages to the users' terminals from the Linux command-line interface.

In this article, we will guide you through the steps on how to send messages to logged-in users in the Linux terminal and also cover the process of checking who is currently logged in, selecting the recipients of the message, and finally sending the message. By following these simple steps, you can communicate with other users on your system without requiring external messaging applications. To do so make sure to read the entire below article.

Here's a step-by-step guide on how to send a message to logged-in users in a Linux terminal −

Step 1 − Check Who's Logged In

To do this, we use the who command in the terminal. When you run this command, it will display a list of all the users who are currently logged in to the system.

The output will include the following information −

  • Login name  The username of the logged-in user

  • Terminal  The device or terminal used by the user to log in

  • Date and time  The time when the user logged in

  • IP address or hostname  The IP address or hostname of the user's system

The who command displays information for all logged-in users in the system. This information can be useful to determine which users are available to receive the message.

In summary, the who command provides a list of currently logged-in users, which is necessary information to choose who you want to send the message to.

Step 2  Choose Who to Send the Message to

If you wish to send a message to everyone who is currently using the Linux system, there's a command that can help you to do this. The command is "wall" and it sends your message to all logged-in users in your particular system. All you have to do is type the "wall" command followed by the message you want to transmit and hit Enter. That's it! It's an easy and direct way to communicate with everyone on the system simultaneously.

Here is an example explaining the same −

wall Hello everyone!

This will send the message "Hello everyone!" to all users who are currently logged in to your system.

To send a message directly to a specific user who is currently logged into your system we can use the "write" command. With this command, you can quickly and easily communicate with a particular user you want without the need for other messaging tools that are available out there. To send a message using the "write" command, simply type the "write" command followed by the username of the intended recipient in the terminal, then enter your message and press "Enter". The message will be delivered to the user's terminal instantly as you hit enter, allowing for simple and efficient communication between users on the system.

Here is an example explaining the same −

write robert Please come to my office

Output for this command −

write: robert is logged in more than once; writing to pts/0
Please come to my office

This will send the message "Please come to my office" to the user with the username "robert" who is currently logged in to the system.

You can also send messages to a group of users using the "wall" command in combination with the "grep" command. For example, if you want to send a message to all users whose username starts with "j",

you can refer to the following command 

who | grep '^j' | cut -d' ' -f1 | xargs -I{} write {} Please come to my office

Output for this command −

robert has been written to
smith has been written to

To send a message to users whose usernames start with "j", you can use a command that lists all logged-in users ("who"), filters out the usernames that don't start with "j" ("grep"), extracts the usernames from the output ("cut"), and then sends a message to each username ("write"). For example, you can send a message to these users saying "Please come to my office".

Step 3  Send the Message

To send the message, you need to type your message after the command (either "wall" or "write") and hit enter.

For example, if you want to send the message "Hello everyone!" to all logged-in users, you can type −

wall Hello everyone!

The "wall" command is used to send messages to all logged-in users, so your message will be telecast to everyone. The message will appear on the terminal screen of every user who is currently logged in.

If you want to send the message "Please come to my office" to a specific user named "robert", you can type:

write robert Please come to my office

To send messages to a specific user the "write" command is used. In this case, the message will only be sent to the user named "Robert" in the system. The message will appear on the terminal screen of the user, along with your username and the time the message was sent.

It's important to note that when using the "write" command, you need to specify the username of the recipient after the command. Additionally, the recipient must be logged in and have an open terminal window in order to receive the forwarded message.

In summary, step 3 involves typing your message after the command and hitting enter to send it to the chosen user(s). The specific command you use will depend on whether you want to send the message to all logged-in users or to a specific user.

Conclusion

In conclusion, sending messages to logged-in users in a Linux terminal is a quick and useful feature that can save you time and effort. It allows you to communicate with multiple users or send notifications to specific users in a matter of seconds.

To send a message, you first need to check who is logged in using the "who" command. Then, you can choose who to send the message to - either all users using the "wall" command or a specific user using the "write" command followed by their username.

Finally, you need to type your message after the command and hit enter to send it to the chosen user(s). The message will appear on the terminal screen of the user(s), along with your username and the time the message was sent.

Overall, this feature is a simple and effective way to communicate with other users on a Linux system. It's particularly useful for system administrators who need to notify multiple users of important information or for individuals who need to communicate with colleagues in a quick and efficient way.

Updated on: 27-Jul-2023

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements