How to use the command 'write' (with examples)
The write
command is used to send messages to other users logged in on the system. It allows you to communicate with other users directly from the terminal. This command is particularly useful for sending urgent messages or notifications to specific users.
Use case 1: Send a message to a given user on a given terminal id
Code:
write username terminal_id
Motivation:
You may need to send a message to a specific user who is logged in on a specific terminal. By using the write
command, you can easily send a message directly to them, ensuring that they receive it promptly.
Explanation:
username
: The username of the user you want to send the message to.terminal_id
: The terminal ID of the user you want to send the message to. You can find the terminal ID by using thewho
command.
Example output:
write johndoe tty/5
message: Hello John, please come to the meeting room ASAP.
Ctrl-C
In this example, a message “Hello John, please come to the meeting room ASAP” is sent to the user with the username “johndoe” who is logged in on terminal ID “tty/5”.
Use case 2: Send a message to a user on a specific terminal /dev/tty/5
Code:
write testuser /dev/tty/5
Motivation: You may need to send a message to a specific user, but you know the exact terminal device they are using. By specifying the terminal device, you can ensure that the message reaches the intended user.
Explanation:
testuser
: The username of the user you want to send the message to./dev/tty/5
: The specific terminal device where the user is logged in. You can find the terminal device by using thewho
command.
Example output:
write testuser /dev/tty/5
message: Hey there, just wanted to check if you received my previous message. Please let me know.
Ctrl-C
In this example, a message “Hey there, just wanted to check if you received my previous message. Please let me know” is sent to the user with the username “testuser” who is logged in on the terminal device “/dev/tty/5”.
Use case 3: Send a message to a user on a pseudo terminal /dev/pts/5
Code:
write johndoe /dev/pts/5
Motivation: You may need to send a message to a user who is using a pseudo terminal. By specifying the pseudo terminal device, you can ensure that the message reaches the intended user.
Explanation:
johndoe
: The username of the user you want to send the message to./dev/pts/5
: The specific pseudo terminal device where the user is logged in. You can find the pseudo terminal device by using thewho
command.
Example output:
write johndoe /dev/pts/5
message: Urgent! Please review the document before the deadline.
Ctrl-C
In this example, a message “Urgent! Please review the document before the deadline” is sent to the user with the username “johndoe” who is logged in on the pseudo terminal device “/dev/pts/5”.
Conclusion:
The write
command is a powerful tool for sending messages to other users logged in on the system. Whether you need to send urgent notifications or simply want to communicate with other users, the write
command provides a convenient way to accomplish this from the terminal. By specifying the target username and the respective terminal device, you can ensure that your messages reach the intended recipients accurately.