JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Sending a message to logged in users in Bash

Author:JIYIK Last Updated:2025/03/22 Views:

This article explores methods to send data to another logged in user in Bash. This article discusses methods to find active users and send them messages.


Finding Online Users in Bash

Before sending data to an online user, you must verify whether the user is online. You can use any of the following commands to get the online users of the system.

  1. w Command: Shows who is logged in and what they are doing.
  2. id with the -un flag: When used with the -u and -n flags, the id command displays the effective user name.
  3. who with the a flag: Displays all logged-in users.

To demonstrate, let's look at who -athe output of the command.

root@abdullah:/home/abdullah# abdullah
pts/0        2022-01-08 12:56 (:0.0)
root@abdullah:/home/abdullah# root
pts/1        2022-01-08 12:56 (:0.0)

pts/0 is a special file for the first terminal (the second output line). Data written to this console will be displayed on the first terminal.

For more information on the above command, use the following command.

man w
man id
man who

A man page (short for man pages) is a Unix utility that displays information about system calls, library calls, formal standards and conventions, and even abstract concepts. Since man pages are downloaded with the kernel, no internet connection is required.


Writing to Online Users Using Bash

Now that we've explored methods for finding logged-in users, we'll look at methods for sending them messages.

The commands below will show you how to send messages to online users through different terminals.

root@abdullah:/home/abdullah# write abdullah pts/0

The above command writes a message to user abdullah on console pts/0. After entering the above command, the terminal will ask you to provide a message prompt.

Type the message (let's say we type: Hello Abdullah) and press CTRL+Z to exit the prompt.

Now, if you see another terminal logged in as user abdullah, it will contain the following:

abdullah@abdullah:~$ Message from root@abdullah on pts/1 at 12:20...
abdullah@abdullah:~$ Hello Abdullah

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Detailed explanation of command return value $? in Linux

Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM

? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re

Common judgment formulas for Linux script shell

Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM

In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –

How to use the Linux file remote copy command scp

Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM

Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial