How to Send Broadcast Message to Users on Linux

How to Send Broadcast Message to Users on Linux

Are you looking for a tutorial on how to send broadcast message to users on Linux? Then this guide is what you need.

Sending individual messages to each user can be tiring and counterproductive. By sending broadcast messages on Linux, you can streamline your communication and save time. It’s an efficient way to make an important announcement to all users at once.

If you’re an IT administrator or a system operator, this guide shows you different ways of sending messages to all currently logged-in users to save you from the pain of manual messaging.

Let’s get started!

How to Send Broadcast Message to Users on Linux

In this section, we’ll discuss the different commands commonly used for sending messages to all local users.

Broadcast Message with the wall command

This is the most common way to send messages to all users that are logged in. This is the syntax of the wall command:

$ wall [-n] [-t timeout] [message | file]

The simplest way to send the message is to write it after the command, like this:

$ wall [message to send]

So for example, if you’d like to notify all users about a system shutdown, the command will look like this:

$ wall "The system will be temporarily shutdown at 06:00 PM due to maintenance"

Output:

How to Send Broadcast Message to Users on Linux

The command will work without the quotes, too, as you can see from the below picture:

How to Send Broadcast Message to Users on Linux

However, having the quotes is good for differentiating between the message and the flags you add.

If you don’t add any message after the command, you’ll be taken to the standard input. After writing the message, press ‘Ctrl + D’ to send it. Here’s how it looks:

$ wall
$ Writing the message in the standard input
$ ^D(Ctrl + D)

Output:

How to Send Broadcast Message to Users on Linux
wall broadcast message

If you’d like to remove the header from the message, you can do that as well. To do that, you add the -n flag, like this:

$ wall -n “Broadcast message without a header” 

Output:

wall message without header

This feature is only available if you’re a root. Other users can’t use this. If you try to do so, then you will get this message:

wall: --nobanner is available only for root

Output:

wall message without header

If you want to display the text of a file as a message instead of writing it, you can do that too. For that, you have to add the file name to the command, like this:

$ wall [file name]

First, let’s create a file. We will use the nano text editor for that. Create a file in nano with this command:

$ sudo nano wall.txt

Type your message inside. For testing, we’re writing “Broadcasting a message directory from a file”.

Output:

nano editor

Save the file with ‘Ctrl + O’ and exit using ‘Ctrl + X’.

Now in the terminal, run this command:

$ sudo wall wall.txt
wall text file

An interesting way to use the wall command is to pipe it with the echo command. This is how you do it:

$ echo "Using echo to broadcast a message" | wall

Output:

write command

Another cool flag is -t or --timeout. Adding this flag ensures that any writing attempt after the specified time is abandoned. You can specify a value yourself or use the default one, which is 300 seconds.

Broadcast Message with the write command

The write command is used for sending messages to other users. This is done by copying lines from your terminal to theirs. So this command is more suitable for communicating with individual users.

This is the basic syntax of the command:

$ write user [ttyname]

And this is the message format the user receives:

Message from [email protected] on yourtty at hh:mm …

A user must be logged in for you to be able to send the message. You can check which users are currently logged in with this command:

$ who

Output:

who command

If you try to send messages to someone not logged in then you will get this output:

write: user is not logged in

Output:

write command

So if you want to message a user named ‘john’, for example, this is how you need to write the command:

$ write john
$ Hey John, are you free at night?
$ I need some help
$ ^D(Ctrl + D)

Now if John wants to reply to you, he needs to do the same.

$ write ali23
$ Hey Ali. Yes, I’m free tonight.
$ What help do you need?
$ ^D(Ctrl + D)

So that’s how users can use the write command for creating a chat session. To terminate it, you have to press ‘Ctrl + C’.

A user can also enable or disable the option to receive such messages. To enable it, you use this command:

$ mesg y

To disable the option, run this command:

$ mesg n

Broadcast Message with the talk command

This is another useful command for instant messaging and chatting with users. Since the talk command is not installed by default, you need to install it first. Simply install it on Ubuntu/Debian by running these commands:

$ sudo apt-get install talk
$ sudo apt-get install talkd

Output:

install talk command
install talk command

For CentOS/Fedora, run this command:

$ sudo yum install talk
$ sudo yum install talk-server

Since these are very small files, it shouldn’t take too long to install.

The syntax for this is as follows:

talk user [-x] [ttyname]

So using our previous example, this is what it would look like with the talk command:

$ talk [email protected]

Message from [email protected]
talk: connection requested by [email protected]
talk: respond with: talk [email protected]

And John would reply in the same manner, like this:

$ talk [email protected]

The good thing about the talk command is that it creates two windows. In one window, the users receive the messages, and in the other, they can write their message. So it feels more realistic when it comes to the chatting experience.

talk command double window

Final Thoughts

This tutorial shows you how to send broadcast message to users on Linux. We’ve covered 3 different commands to achieve this. We tried to show you in detail how to use each command, the goods of each one, and how to make the best out of each command.

If you have any questions, feel free to let us know in the comments below.

If this guide helped you, please share it.

Related Posts