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

Running Regular Expressions in Case Statements in Bash

Publish Date:2025/03/22 Views:75 Category:OPERATING SYSTEM

This article explores regular expressions, their basic syntax, and how to run them in Bash using case and if-else constructs. Introduction to Regular Expressions A regular expression, also called regex or regexp, is a sequence of characters

Bash copy all files from remote directory

Publish Date:2025/03/22 Views:156 Category:OPERATING SYSTEM

This article describes methods for copying files between different hosts on a network. It also explores the scp command and how to use it to copy files from a remote location. scp command Secure Copy Protocol (SCP) is a secure copy network

Batch file to loop through files in subdirectories

Publish Date:2025/03/22 Views:96 Category:OPERATING SYSTEM

This article explains how we can write a batch script to loop through files in subdirectories. We will take an example to explain the concept. Batch file to loop through files in subdirectories Assume we have the directory structure shown b

Batch file to remove X characters from a file name

Publish Date:2025/03/22 Views:153 Category:OPERATING SYSTEM

This article explains how we can remove specific characters from the filename of a file using a batch script. We will cover several methods below to rename files on Windows. File Explorer Renaming on Windows File Explorer offers the least f

Declaring variables in batch script

Publish Date:2025/03/22 Views:65 Category:OPERATING SYSTEM

This article will demonstrate how to declare and define variables in a batch script. Declaring variables in batch script In Batch, you do not need to use any additional keywords to declare integer, float, double, or string type variables. T

Batch Check for Empty Variables

Publish Date:2025/03/22 Views:86 Category:OPERATING SYSTEM

This article explains how we can test if a variable has been set. We can use an if statement to check if a variable has been defined. Batch check whether variables are empty For a simpler context, we will start by defining two strings, str1

Floating-point arithmetic in Bash

Publish Date:2025/03/22 Views:189 Category:OPERATING SYSTEM

This short article describes how to quickly perform floating-point calculations in GNU BASH (shell scripts) directly at the command prompt or in a shell script. If you work with numbers, it can be helpful to perform quick floating-point cal

Writing to a File in Bash

Publish Date:2025/03/22 Views:133 Category:OPERATING SYSTEM

This article will let us explore different ways to write files in bash. Files can be appended or overwritten as required. Let's see how we can do it. Different ways to write/overwrite files in Bash We will see several operators, such as and

Terminating a Process in Bash

Publish Date:2025/03/22 Views:135 Category:OPERATING SYSTEM

This article will first discuss the different concepts related to Linux processes. After this, we will learn the different ways to terminate a process. Before going into the kill command, we must understand some preliminary concepts. Simple

Scan to Read All Tech Tutorials

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

Recommended

Tags

Scan the Code
Easier Access Tutorial