In: Computer Science
Explanation on how the mesg, write, and wall commands can be used to allow users to talk to each other on UNIX:
mesg command: It is a utility invoked by a user to control others' write access to the terminal device associated with standard error output. When write access is allowed, write(1) and other programs either display or does not display messages from other users on the terminal. It controls if non-root users can send messages to your terminal.
Syntax:
mesg [option] [y|n]
y: Allows write access to a user's terminal.
n: Disallows write access to the user's terminal.
Example:
mesg y
write command: It is a utility allowing one user to communicate with other users. It sends a message to another or other users copying lines from one user's terminal to others'. Thus, users are able to talk to each other. When this 'write' command is run, one user writes to get a message of the below form:
Syntax:
write user [tty]
Example:
write John
Writes a message to the user John.
When the command is entered, the user will be placed at a blank line, he/she can type everything which will be sent to the other specified user. Pressing the interrupt character i.e., Ctrl + C, returns the user to the command prompt terminating the write session.
Message from username@userhost on usertty at hh:mm ...
Any subsequent lines the user enters are copied to the specified
user's terminal.
For the other user to reply he/she also uses the same 'write'
command.
wall command: This command writes a message to all users, thus a user talks to one another or all. It basically, displays a message or the contents of a file, or its standard input, on all the currently logged in users' terminals. The command truncates any lines over 79 characters to new lines.
Syntax: wall [-n] [-t timeout] [-g group] [message | file]
Options:
-n: No banner. It suppresses the banner.
-t: It ignores the write attempt to the terminals after certain
timeout seconds.
-g: It limits printing message to members of a group defined as a
group argument.
Example:
wall test.txt
This command sends or writes the contents of test.txt file to all users.