Overview
Multi-user Linux environments rely heavily on standard I/O abstractions, allowing users to send direct text transmissions across active terminal sessions using the classic write utility. Underneath the hood, this mechanism interfaces straight with pseudo-terminal (pts) device files. This walk-through breaks down the foundational communication model governing TTY/PTS subsystems alongside practical terminal workflows to inspect, configure, and troubleshoot direct inter-session messaging.
1. Inspecting Active Sessions and Terminal Devices (TTY/PTS)
Executing whoami reveals the effective username operating within the active shell session.
In this test execution, the terminal confirms that operations are currently carried out by the privileged root account.

To identify the standard input device file bound to the current shell context, issue the tty command.
Because this particular command ran inside an automated, non-interactive execution pipeline without an attached pseudo-terminal device, the system returns not a tty.

The who utility queries system state to list all currently authenticated users, their corresponding terminal device nodes, and their respective login timestamps.
When no interactive sessions are registered on the host, the command terminates cleanly with an empty output buffer.
⚙️ [Essential Command-Line Flags]
-u : Appends detailed runtime session metrics, including idle intervals and associated process IDs (PIDs).-a : Dumps comprehensive system accounting data spanning runlevels, boot times, and dead background login processes.-b : Displays the exact timestamp of the most recent system startup.-q : Emits a condensed summary listing only active user handles alongside a total connection count.-H : Prints clear, structured column headings across the tabular terminal report.

2. Managing Terminal Write Permissions: Querying and Modifying mesg
Run the standalone mesg utility to inspect whether the current terminal permits inbound message broadcasts from other users.
Invoking this command without extra arguments reports the active reception policy of the terminal session.

To explicitly permit incoming terminal transmissions from peers across the system, execute mesg y.
The utility exits silently upon successfully applying the write-allow policy to the underlying terminal session.

To examine how this state change reflects at the filesystem level, run ls -l $(tty).
Toggling access through mesg directly manipulates the discretionary write permission bits on the associated device node in /dev/pts/.

3. Transmitting Real-Time Text Messages via write
To isolate the device identifier and assign it to a working shell variable, execute TARGET_TTY=$(tty | sed 's|/dev/||').

Next, leverage write to relay real-time stream data directly into the target user’s active console.
Piping string buffers into write pushes that text stream immediately onto the recipient’s display screen.

4. Validating Internal write Mechanics via Direct Device I/O
Run echo "[DIRECT WRITE] Testing direct write to terminal device." > $(tty) to push arbitrary text directly into the terminal special file.
This fundamental exercise demonstrates that the write binary merely acts as a managed wrapper around direct I/O writes targeting character device endpoints allocated in /dev/pts/.

To block unsolicited incoming console interruptions, issue mesg n.
Once restricted, remote write operations targeting this terminal instance are systematically rejected by the operating system.

To verify the permission delta triggered by the restriction, run ls -l $(tty).
Executing mesg n revokes group write permissions on the character device file, preventing non-privileged system accounts from injecting data onto the display.

To reinstate message reception, re-enable permissions using mesg y.
This re-adds write permissions for the terminal’s owning group, reopening the session to standard peer-to-peer terminal transmissions.

We have explored the low-level communication mechanics behind the classic write tool, examining how UNIX character devices and permission masks govern inter-terminal messages.
Mastering these terminal controls provides invaluable clarity when managing multi-tenant Unix/Linux shells and debugging pseudo-terminal behavior.