Linux write Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux write command to send messages to specific users or broadcast messages to all logged-in users on the same system. The lab covers the purpose and syntax of the write command, how to send a message to a specific user, and how to broadcast a message to all logged-in users. The steps provided in the lab will guide you through these practical examples, helping you understand the usage and application of the write command in a Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") subgraph Lab Skills linux/echo -.-> lab-423011{{"`Linux write Command with Practical Examples`"}} end

Understand the Purpose and Syntax of the write Command

In this step, you will learn about the purpose and syntax of the write command in Linux. The write command allows you to send a message to another user who is currently logged in to the same system.

To use the write command, you need to know the username of the user you want to send the message to. The basic syntax of the write command is:

write username

After running this command, you can type your message, and press Enter to send it. To end the message, type Ctrl+D.

Example:

$ write labex
Hello, this is a test message.
^D

Example output:

Message from labex@ubuntu on pts/0 at 14:45 ...
Hello, this is a test message.
EOF

In the example above, the write command was used to send a message to the user labex. The message was "Hello, this is a test message." and the ^D (Ctrl+D) was used to indicate the end of the message.

The recipient of the message will see the message displayed on their terminal, along with the username and time the message was sent.

Send a Message to a Specific User on the Same System

In this step, you will learn how to send a message to a specific user who is currently logged in to the same system.

To send a message to a specific user, you can use the write command followed by the username of the recipient. For example, to send a message to the user labex, you would use the following command:

write labex

After running this command, you can type your message, and press Enter to send it. To end the message, type Ctrl+D.

Example:

$ write labex
This is a message for labex.
^D

Example output:

Message from labex@ubuntu on pts/0 at 14:50 ...
This is a message for labex.
EOF

In the example above, the write command was used to send a message to the user labex. The message was "This is a message for labex." and the ^D (Ctrl+D) was used to indicate the end of the message.

The recipient of the message will see the message displayed on their terminal, along with the username and time the message was sent.

Broadcast a Message to All Logged-in Users

In this step, you will learn how to broadcast a message to all users who are currently logged in to the same system.

To broadcast a message, you can use the wall (write all) command. This command sends the message you type to the terminals of all logged-in users.

The syntax for the wall command is:

wall

After running this command, you can type your message, and press Enter to send it. To end the message, type Ctrl+D.

Example:

$ wall
Attention all users! This is an important announcement.
^D

Example output:

Broadcast message from labex@ubuntu on pts/0 at 14:55 ...

Attention all users! This is an important announcement.

In the example above, the wall command was used to broadcast a message to all logged-in users. The message was "Attention all users! This is an important announcement." and the ^D (Ctrl+D) was used to indicate the end of the message.

All logged-in users will see the message displayed on their terminals, along with the username and time the message was sent.

Summary

In this lab, you learned about the purpose and syntax of the write command in Linux, which allows you to send a message to another user who is currently logged in to the same system. You also learned how to send a message to a specific user on the same system using the write command followed by the username of the recipient. Additionally, you explored how to broadcast a message to all logged-in users on the system.

The lab provided practical examples and step-by-step instructions to help you understand and apply the write command effectively. By the end of the lab, you should have a solid grasp of how to use the write command to communicate with other users on the same Linux system.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like