Saturday, June 6, 2009

Broadcast messages to other users in Linux

Ever been connected to a multiuser Linux machine and wanted to broadcast a message to other users? Well there are a couple of ways to to this. If you want to broadcast a global message to all users then you will want to use the wall program. This tool reads from the standard input, which means that you will need to use the pipe functionality to send the results of other commands into it. For example:
echo "my message" | wall
This will print "my message" onto the terminal of all other users. Really though you can output the results of any command into wall.

If you only want to broadcast a message to another specific user, you can use the write program. The syntax for this command looks like this:
write [username] [TTY]
The username will specify which user you want to send messages to. TTY tells the system how that user is connected. You can obtain this by using this command:
w [username]
This will print out the username, TTY, where they are connected from if it is a remote connection, when they logged in, how long they have been idle for, some information about process times and if they are running any programs right now. If you run the w program without a username as an argument it will print this information for all connected users.

So connecting to a user named "phil" might look something like this:
write phil pts/2
Your prompt will disappear and anything you type will be sent to phil. If the other user wants to send messages back, he will have to use the write program to connect to you first. The other user will also get to see who is sending him messages.

To stop using the write program press ctrl+c to kill the current foreground process. If you want to intermittently send messages to another user and work on something else you can keep the write session alive by pressing ctrl+z. This will send the foreground task to the background and until called back to the forground by typing:
If you don't want to receive messages in this way you can turn it off or back on with:
mesg [y/n]
If you use "n" as an argument it will disallow messages and if you use "y" it will allow messages. To see the current value just use the mesg command without any arguments.


  1. This is a great idea when you are messing with system processes and want to inform all other users who are logged into the system. And its also great to screw with freshman who have never used a linux os before. One idea is to wall make sure you send them a message in the middle of the running of their program so that their output gets screwed up.

  2. Thanks. This cleared a few things up for me. I had been wondering why other users were receiving no messages after running wall with sudo. "mesg y"!

  3. Thanks . usefull page here.

  4. Thanks, very informative article.

    Can we send message to particular user using wall ?