
mesg Command in Linux
The mesg command in Linux is used to manage whether or not you can receive messages on your terminal. In systems with multiple users, both administrators and users can send messages to each other. However, there may be times when you don't want to receive messages, especially when you're busy with important work or tasks.
The mesg command gives you control over this by letting you decide if you want to allow or block messages from others. It helps you manage when and if you want to be disturbed by messages while using your terminal.
Table of Contents
Here is a comprehensive guide to the options available with the mesg command −
- What is mesg Command in Linux?
- Syntax of mesg Command
- Installation of mesg Command in Linux
- Examples of mesg Command in Linux
What is mesg Command in Linux?
The mesg command helps control message permissions on a Linux system. It lets users choose whether to accept or block messages from others on the same system. In multi-user systems, where several people share the same machine, the mesg command can help maintain privacy by preventing messages from other users.
For example, during server maintenance, administrators often use the wall command to send messages to all logged-in users. If a user prefers not to receive these messages, they can use the mesg n command to block incoming messages.
Key Features
The mesg command offers several features that are listed below −
- Manage Messages − The mesg command lets you turn on or off receiving messages from other users on the system.
- Privacy Control − It helps block unwanted messages, giving you more control over your privacy.
- Easy Toggle − You can quickly turn messages on with mesg y or off with mesg n.
- User-Specific − Each user can control their own message settings.
- Works with write and talk − It controls messages sent through the write or talk commands.
- Check Status − You can check the status of the currently allowing or blocking messages by running the mesg command without any option.
Syntax of mesg Command
The basic syntax of the mesg command is as follows −
mesg [y | n]
You can use mesg y to allow messages to be received or mesg y to deny the messages. However, if you do not specify any option, it shows whether you can receive messages or not.
To learn more about the mesg command, access the general manual page by executing the following command −
man mesg

Installation of mesg Command in Linux
The mesg command is generally pre-installed on most Linux distributions as part of the standard tools for managing user terminals and messages. You generally don't need to install it manually unless it's missing from your system. If that's the case, you can use your distribution's package manager to install it.
You can confirm the command availability on your system by checking its version as follows −
mesg --version

Examples of mesg Command in Linux
Let's go through some practical examples to understand the practical usage of the Linux mesg command.
Viewing Current Settings
Let's run the mesg command without any option to view the current settings of the mesg −
mesg
The output shows that we can receive messages from other users −

Allowing or Denying Messages
We can use the y or n option to allow or deny messages, respectively. For example, the following command restricts other users from sending us messages.
mesg n
After this, execute the mesg command with any option to make sure the changes have been applied successfully −

To re-enable the messages from other users, you can use the following command −
mesg y
Sending Messages to a User
To send a message to a specific user, you can use the write command as follows −
write user_name
Replace the user_name with the actual user to whom you want to send messages. After this, you can specify the message that you want to send to the user. Finally, press CTRL + D to send the message.
Sending Messages to All Users
To send a specific message to all users, you can use the wall command. For this purpose, you must specify the wall command followed by the message to be sent −
wall "Hi users! tutorialspoint.com will be going down for maintenance in 15 minutes."
This command will send the specified message to all the users of this device.
Conclusion
The mesg command is a simple but useful tool for managing communication in systems with multiple users. Whether you're an admin managing many users or someone who wants to avoid distractions, mesg lets you control when and how you receive messages on your terminal. This command is especially helpful in larger systems or when you're focused on important tasks and don't want to be interrupted by others.
In this tutorial, we explained what is mesg and how to use it to allow or deny incoming messages from other users.