Introduction
Scenarios in which multiple users use SSH to work on a server simultaneously are common in the Linux world. When system administrators perform system maintenance tasks, they need a quick way to inform users they should save their work and log out.
In this tutorial, you will learn how to use the wall
command in Linux. This command allows sending terminal messages to all logged in users at once.
Note: wall
is a terminal-based command. Users working in a GUI without a terminal window open will not see wall notifications.
Prerequisites
- A system running Linux
- Access to the command line
What Does the wall Command Do?
wall
is short for write to all. The purpose of the command is to send a quick message to the terminals of all currently logged in users.
Linux wall Command Syntax
The syntax of wall
is straightforward. The command is followed by options and either the text of the message or a filename:
wall [options] [message-text/filename]
wall Command Examples
Below is a list of all the options wall
takes, along with examples of the command use.
Broadcast a Message
The basic way to use the Linux wall
command is to type it before a message you want to send, without any added options.
wall [message-text]
The users receive the message in the following format:
Note: Use the wall
command sparingly. It was designed for communicating essential pieces of information, so it reaches all the logged in users under all conditions. Frequently using the command when there is no need for it may disrupt the workflow for some users.
Add a Timeout to a Message
If the contents of the message become irrelevant after a certain period, use the -t
(--timeout
) option to limit the time during which the system attempts to deliver the message:
wall -t [time-in-seconds] [message-text]
Users who log in after the allotted time expires do not receive the message.
Broadcast a Message Without the Header
To exclude the header text preceding the message, use the -n
(--nobanner
) option:
wall -n [message-text]
The system now displays only the contents of the message:
Write Multi-line Messages
1. To write a message containing multiple lines, type the wall
command and press Enter. The terminal provides the user with space to enter the message.
2. Once you finish writing, press Ctrl+D to end the input and send the message.
wall
[message-line-1]
[message-line-2]…
The system displays the multi-line message on the users’ screens:
Broadcast a Message from a File
To use text contained in a file as the wall message, write the filename after the wall
command:
wall [filename]
The output for the users receiving the message looks the same as in the previous examples:
Broadcast a Message to a Group
Limit the reach of the wall
command to include only a certain group of users by using the -g
(--group
) option:
wall -g [group-name] [message-text]
In the example above, only the users belonging to testgroup
receive the message.
Use the wall Command with echo
Another way to send a message using wall
is to pipe the output of the echo command into wall
using the following syntax:
echo "[message-text]" | wall
Display Version Information and Help
Use the -V
(--version
) option to see the installed wall utility’s version information:
wall -V
The -h
(--help
) option lists all wall
command options:
wall -h
Conclusion
After reading this tutorial, you should understand how to use the wall
command in Linux. The tutorial covered all available options and offered practical examples of using the command.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/cloud/223861.html