mesg
Control write access to your terminal
TLDR
Check terminal's openness to write messages
Disallow receiving messages from the write command
Allow receiving messages from the write command
SYNOPSIS
mesg [y|n]
PARAMETERS
y
Allows other users to write messages to your terminal.
n
Prevents other users from writing messages to your terminal.
DESCRIPTION
The mesg command controls whether other users can send messages to your terminal using commands like write or talk.
In a multi-user Linux environment, this feature allows users to communicate directly by sending text to another user's active terminal session. While useful for quick notifications, it can also be intrusive. The mesg command provides a simple way to manage this.
When run without arguments, mesg reports its current status, indicating whether messages are allowed or denied (e.g., "is y" or "is n"). By default, many systems might have messaging enabled upon login. Using mesg y explicitly permits messages, making your terminal accessible to other users for direct communication. Conversely, mesg n disallows messages, preventing unsolicited text from appearing on your screen and providing a level of privacy and control over your workspace. This command is particularly relevant in shared computing environments or academic settings where direct terminal interaction might still be common.
CAVEATS
The mesg command controls access for regular users. It does not prevent the superuser (root) from writing to your terminal, for example, using commands like wall.
The setting is typically applied per terminal session (TTY). If you have multiple sessions open, you may need to set mesg individually for each.
Your shell's initialization files (.profile, .bashrc, etc.) or the system's login process might set a default mesg status upon login, potentially overriding a previous setting.
CHECKING CURRENT STATUS
To check the current message status for your terminal, simply run mesg without any arguments. It will output "is y" if messages are allowed, or "is n" if they are denied. You can also observe the output of the who command; a plus sign (+) next to a user's terminal indicates that messages are allowed, while a minus sign (-) indicates they are denied.
MULTIPLE TERMINAL SESSIONS
If you are logged in multiple times (e.g., through different virtual terminals, SSH sessions, or graphical terminal emulators), the mesg setting is specific to each tty (teletypewriter) session. Changing it in one session will not affect the others.
HISTORY
The mesg command has been a standard utility in Unix-like operating systems for many decades, tracing its roots back to early Unix versions. Its primary function was to facilitate and control direct, synchronous communication between users on shared mainframe or minicomputer systems where users often logged into the same machine. In such environments, direct terminal-to-terminal messaging via commands like write was a primary form of real-time interaction. While its direct interactive use has diminished in prevalence with the advent of more sophisticated communication tools (email, instant messaging, chat platforms), mesg remains a fundamental part of the Unix toolset, ensuring backward compatibility and providing control over an underlying system feature.