Linux常用命令-write

命令

write

描述

send a message to another user
发送消息给其他登录用户

用法

1
write user [ttyname]

选项

注意

注意输出内容会打断当前的命令行
wall命令是发送到所有终端,write命令是发送到指定用户终端

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 可以先通过w或who命令查看当前登录的用户
$ w
21:45:07 up 1:25, 3 users, load average: 0.00, 0.01, 0.04
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 20:19 6:03 0.05s 0.05s -bash
root pts/0 192.168.80.1 21:28 3.00s 0.08s 0.00s w
root pts/1 192.168.80.1 20:22 19.00s 0.66s 0.66s -bash
$ who
root tty1 2021-03-20 20:19
root pts/0 2021-03-20 21:28 (192.168.80.1)
root pts/1 2021-03-20 20:22 (192.168.80.1)

# 终端1发送hi到终端2,结束发送按ctrl+d
$ tty
/dev/pts/0
$ write root /dev/pts/1
hi
$
Message from root@node1 on pts/1 at 21:43 ...
hello
EOF

# 终端2回复hello给终端1,收到的消息以EOF结尾表示消息发送完成,否则表示消息正在发送
$ tty
/dev/pts/1
$
Message from root@node1 on pts/0 at 21:42 ...
hi
EOF

$ write root pts/0
hello