How to Send a Message to Logged Users in Linux Terminal?
Last Updated :
09 Apr, 2025
Linux is a solution to the data center. It is flexible, stable, secure, and reliable. There are many users logged into servers for development purposes, testing, and usage. There are various tools to send messages to other users, but they do not allow widespread sending or sending to specific users due to security issues, so we're limited to sending messages via terminals.
Checking Active Users on Terminal
To view the active users on the system, use cat utility to get a list of users who are active or the users who are on the system.
$ cat /etc/passwd | cut -d: -f1

Sending Messages to Currently Logged-in Users
To check who is currently logged in and on which terminal the user is logged in will be displayed when w command is executed. w command will display who has logged into the terminal and the actions they are performing.
It displays information about current users on the machine by reading the file /var/run/utmp and their processes /proc. This command comes with a header that displays system activity like current time, system uptime, number of users logged on,
W command invokes without any option and provides information in the following format,
- 10:29:40: The current system time
- up 39 min: Length of time the system has been up
- 1 user: Number of logged-in users
- load average: 2.04, 2.16, 1.49: System load average for the past 1, 16, and 49 minutes. System Load Average is the measurement of the number of jobs that are currently running or waiting for disk I/O.
The Second line includes
- USER: Name of the logged user.
- TTY: Name of the terminal used by the useR
- FROM: Host name or IP address from where the user is logged in
- LOGIN@: Time when the user logged in
- IDLE: Time since the user last interacted with the terminal
- JCPU: Time used by all processes attached to the tty
- PCPU: Time used by the user’s current process. The one displayed in the WHAT field
- WHAT: User’s current process and options/arguments

If you want to view all the users logged into the system and remove the header part then use, who command
$ who

who command gives output with a formatted list of users currently logged into the system. The line has four fields to display,
- NAME of the user logged in
- USER'S Terminal
- The TIME user logged in
- HOSTNAME or IP ADDRESS from where the user logged in
Now to send messages to all users, use the wall command, it comes pre-installed in all Linux Distributions which will allow us to send messages to another user in the terminal using tty2. You can use any symbol, character, or white space in the message. After typing the message use CTRL + D to send the message to all users.
$ wall "Hey, Everyone! Hope Everyone's fine."

Sending Messages to Logged-in Users
To send messages to users logged in even though they are not active. write command is pre-installed in all the Linux Distributions and allows us to send messages to another user in the terminal using tty2. After entering text click CTRL+D to exit when done, it'll then send the text, but it isn't a two-way conversation
$ write root tty2
"We're under Surveillance!!"

While executing to write the command if it doesn't operate or if it is disabled, then use mesg command to turn it on. After which write command will be executed.
$ write root tty2
$ mesg

To give permission to the write command execute mesg y statement to enable write. The command mesg can also be used if the user doesn't want to receive any messages or turning off the incoming messages.
$ mesg y
$ write root tty2

If the message or text is stored in a text file then use the cat utility function with the write command to send the text file to the user in order to send the message. The text file will be sent to all the users logged in irrespective of being active at that particular time. The user can view the message whenever they are active on the Terminal.
$ cat sample.txt | write root tty2

Make use of these commands and methods to send messages to currently logged-in users or users who are logged in but not active in the terminal.
Syntax
Usage:
mesg [options] [y | n]
Control write access of other users to your terminal.
Options:
- -v, --verbose explain what is being done
- -h, --help display this help
- -V, --version display version
Examples
1. Check the Current Status
To check whether your terminal is currently allowing messages, you can simply run mesg
without any arguments.
mesg
- Output
is y
means messages are allowed. - Output
is n
means messages are not allowed.
2. Allow Messages
To allow messages from other users:
mesg y
3. Disallow Messages
To disallow messages from other users:
mesg n
Checking the Status of All Terminals
As a system administrator, you might want to check the message status for all users' terminals. You can use the who
command along with mesg
to check this:
who -T
The output includes a +
sign next to the terminal name if messages are enabled and -
if messages are disabled.
Similar Reads
Shell Script to Find How Many Terminals Has User Logged-In Here we are going to see Find How Many Terminals Has User Logged In. Using who command to fetch the user list and then using grep command we can find the number of Terminal that the user has logged in the Linux. We can use LOGNAME or UID to identify the user. UID is a unique User ID assigned to ever
2 min read
Shell Scripts to Find How Many Users are Logged In Every operating system provides a feature of multiple user accounts. Linux-based operating systems have some commands or functionalities to check user accounts' details and change them. This ability is mainly used by the admin account user that is the root user, to provide permissions and access to
7 min read
How to Monitor Logs in Linux? Monitoring logs in Linux is crucial for troubleshooting, system maintenance, and ensuring optimal performance. Linux logs provide valuable information about the system, applications, and services running on your machine. These logs help administrators diagnose issues and monitor system health. In th
4 min read
How to Force User to Change Password at Next Login in Linux Ensuring strong password policies is important for Linux system security. For security reasons, you must frequently change the password of accounts on the system. In this article, we are going to see how we can force the user to change the password on the next login in Linux. We can do that by two m
6 min read
How to use SSH to connect to a remote server in Linux | ssh Command Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th
8 min read