Master the Linux ‘mesg’ Command: A Comprehensive Guide

Peter Hou
2 min readMay 24, 2023

--

This guide offered a comprehensive overview of the Linux mesg command. Understanding this command is important for privacy and control in a multi-user environment. Its simplicity makes it accessible to beginners, while its usefulness makes it important for more advanced users as well.

Instructions

In this guide, we’ll provide a detailed overview of the Linux mesg command, useful for controlling write access to your terminal. We'll cover its history, when and why to use it, how to use it, its commonly used parameters, common use cases, any tricky skills related to it, important notes, and finally, a conclusion summarizing everything.

History

The mesg command has been a part of Unix-like systems, including Linux, from their early days. It was designed to control the permission other users have to write to your terminal.

When and why to use it

mesg is useful when you want to control whether other users can write to your terminal. This is especially useful in multi-user environments where privacy or interruption concerns may warrant the blocking of unsolicited messages.

How to use it

Using the mesg command is straightforward. You simply type mesg followed by the desired option.

$ mesg n

In this example, the command will deny write access to your terminal.

The commonly used parameters

There are two main options that are used with mesg:

  • -n: This option denies write access to your terminal.
$ mesg n
  • -y: This option allows write access to your terminal.
$ mesg y

Other supported parameters

The mesg command also supports standard Linux command options such as:

  • --help: Display a help message and exit.
  • --version: Output version information and exit.

Most common use cases

One of the most common uses of mesg is to block messages when focusing on a task or to avoid unsolicited interruptions in a multi-user environment.

$ mesg n

The tricky skills

While mesg is a simple command, an interesting technique can be using mesg in conjunction with the write command to control who can send you messages at any given time.

What needs to be noted

Remember that the settings you choose with mesg are only valid for the current terminal session. If you log out or start a new terminal session, you'll need to set your mesg preferences again.

Conclusion

The mesg command is a simple but important tool for controlling write access to your terminal in a Linux environment. Its straightforward functionality makes it a command that every Linux user should be familiar with.

--

--

Peter Hou
Peter Hou

Written by Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.

No responses yet