This topic is fairly known to most older system administrators however I doubt it is used very often anymore. If you happen to manage any servers where there are typically various people logged in and working on different items from the CLI then it can be useful to be able to send them messages. Using the write command you can send messages to users logged in on specific TTY port or by username. Below are a couple examples of how you would use the write command from a Linux shell.
First you would want to verify what users are logged into the system by using the “w” command as shown in the below example. The w command on Linux will display information about each user that is logged into the system.
Use w To Verify Users Logged Into Linux Server:
- [root@dev ~]# w
- 17:06:47 up 7 days, 19:18, 3 users, load average: 0.03, 0.10, 0.05
- USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
- root pts/1 192.168.1.96 17:00 0.00s 0.04s 0.00s w
- alex pts/2 192.168.1.96 17:03 1:22 0.02s 0.02s -bash
- alex pts/3 192.168.1.96 17:05 1:41 0.01s 0.01s -bash
Notice in the above example there are three users logged into the system which include the root user (the user who issued the who command) and the user alex is logged in twice. If only one alex user was logged in then you could simply use “write alex” from a terminal window to begin messaging that user but because alex is logged in twice the system will pick one instance (the instance with the lowest idle time) of the user to message as shown below.
Message A User From A Linux Terminal Window:
- [root@dev ~]# write alex
- write: alex is logged in more than once; writing to pts/2
This user will be notified that you are attempting to message them. So an example of what the user alex on TTY port pts/2 would see is below.
Notification That Another User Is Sending A Message Via Write:
- [alex@dev ~]$
- Message from root@dev.example.com on pts/1 at 17:11 ...
Now when a message is typed by the root user to send to the alex user you must hit “enter” after each line for the message to send as shown below.
Linux CLI Write Example:
- [root@dev ~]# write alex
- write: alex is logged in more than once; writing to pts/2
- hello. just sending a test message
The alex user logged in on TTY port pts/2 would see the below message appear.
Linux Terminal Window Receiving Messages From Another User Via Write:
- [alex@dev ~]$
- Message from root@dev.example.com on pts/1 at 17:13 ...
- hello. just sending a test message
That is all there is to it. The write command is rarely used anymore and hasn’t been updated since 1995 so you can see it is fairly old however it can be very useful to message another user during software installations or other Linux server system maintenance if you don’t know of another way to contact them.