Linux wall 新手命令教程(附实例)
有时多个用户登录到服务器计算机,而您(系统/网络管理员)需要重启服务器以执行某些维护任务。当然,正确的方法是将维护活动通知所有登录的人。
值得庆幸的是,Linux 为此提供了一个内置的命令行实用程序。所讨论的工具是 Wall,在本教程中,我们将使用一些易于理解的示例来讨论该工具的基础知识。但在我们这样做之前,值得一提的是,本文中的所有示例都已在 Ubuntu 22.04 LTS 机器上进行了测试。
Linux 翻墙命令
如前所述,wall 命令用于向所有登录用户发送消息。以下是它的语法:
wall [-n] [-t TIMEOUT] [file]
以下是工具手册页对其的描述:
Wall displays the contents of file or, by default, its standard input, on
the terminals of all currently logged in users. The command will cut over
79 character long lines to new lines. Short lines are white space padded
to have 79 characters. The command will always put carriage return and
new line at the end of each line.
Only the super-user can write on the terminals of users who have chosen
to deny messages or are using a program which automatically denies mes?
sages.
Reading from a file is refused when the invoker is not superuser and the
program is suid or sgid.
以下是一些 Q&A 风格的示例,应该可以让您对 wall 命令的工作原理有一个很好的了解。
Q1。如何使用墙命令?
基本用法非常简单 - 只需执行 wall 命令并在标准输入上写入您要传输的消息。完成后,使用 Ctrl+D 组合键向命令发出您已完成编写消息的信号。
wall
例如,这是在 stdin 上输入文本的第一步:

下面是多次按下Ctrl+D,广播消息的第二步:

以下是其他登录用户看到消息的方式:

Q2。如何从广播消息中剥离标题?
如果你想删除与广播消息一起出现的标题,你可以使用 -n 命令行选项来实现。
wall -n
例如,以下操作:
wall -n
Message without header
^D
产生了以下输出:

Q3.如何让墙接受来自文件的输入?
这可以通过将文件名作为输入传递给 wall 命令来实现。
wall [filename]
例如:
wall input.txt
其中 input.txt 包含以下行:
This message is from a file

这是输出:

Q4.使用 wall 命令的其他方法是什么?
还有一些其他方法可以使用 wall 命令。例如:
echo "test message" | wall
wall << .
> test message
> .
wall <<< "test message"
结论
总而言之,如果您是系统/网络管理员,那么 wall 命令是必须知道的,并且您的大部分工作都涉及管理多个用户使用的无头服务器。我们已经讨论了 wall 命令的大部分功能。要了解更多信息,请前往工具 cd 命令教程。