In Linux environments, pts
(pseudo-terminal slave) refers to virtual terminal devices created for user sessions. When you run the who
command, you'll see output like this:
user1 pts/0 2023-04-15 14:30 (192.168.1.10)
user2 pts/1 2023-04-15 14:32 (192.168.1.15)
The simplest way to send a message is using the write
command:
write username pts/number
For the example in question:
write yang pts/6
After executing this command, type your message and press Ctrl+D to send. The recipient will see:
Message from yang@hostname on pts/3 at 10:30 ...
Hello there!
EOF
For more control, you can pipe messages directly:
echo "Server maintenance in 5 minutes" | write yang pts/6
Or send from a file:
write yang pts/6 < message.txt
To send to all users (requires root):
echo "EMERGENCY: System rebooting NOW" | wall
If messages aren't delivered:
- Check if the user has messaging disabled with
mesg n
(enable withmesg y
) - Verify the pts session still exists with
who
- Try the full format:
write yang@10.231.22.12
For interactive chatting:
talk yang@10.231.22.12
In Unix/Linux systems, pts
(pseudo-terminal slave) devices represent virtual terminals created for user sessions. When you run the who
command, it displays active terminal sessions like this:
user1 pts/0 2023-01-15 14:30 (192.168.1.10)
user2 pts/1 2023-01-15 14:35 (192.168.1.20)
There are several ways to send messages to terminal sessions:
# Method 1: Using write command
write username pts/1
# Method 2: Using wall (broadcast to all)
echo "Message" | wall
# Method 3: Using mesg utility
mesg y # Enable receiving messages
To target a specific pts
device directly:
# Method 1: Using echo to the device file
echo "Hello from terminal" > /dev/pts/1
# Method 2: Using write with terminal specification
write user1 pts/1
Here's a complete example of sending a message programmatically:
#!/bin/bash
# Get target pts from who output
TARGET_PTS=$(who | grep username | awk '{print $2}')
# Send message
echo "Important system notification" > /dev/$TARGET_PTS
# Alternative with formatted message
printf "\033[1;31mURGENT:\033[0m System maintenance in 5 minutes\n" > /dev/$TARGET_PTS
Remember that:
- User must have
mesg y
set to receive messages - You need appropriate permissions to write to the pts device
- Sudo might be required for system-wide messaging
If messages aren't being received:
# Check if user has messages enabled
who -T | grep username
# Verify terminal device exists
ls -l /dev/pts/