Send A Message To Another Logged In User

Today’s article might be useful for system administrators or just for fun, as we learn to send a message to another logged-in user (in the terminal, of course). This shouldn’t be a complicated or lengthy article, though many of my recent articles have been significantly longer than usual.

If you’re just a regular desktop user, this might not be all that interesting, but you can still test it if you want. Besides, you never know when you will want to send a message to another logged-in user! It could happen.

Let’s say you have a server with people logged in via SSH. This could also be a single computer with multiple people logged in, should you wish to test this and play around with sending a message to another logged-in user. Let’s also say that you want to send them a message in the terminal.

Perhaps you’re going to log them off? Maybe you’re going to reboot the server? Who knows, maybe you want to give them some sort of directions and the easiest way to do so is to send them a message that pops up in their terminal. You can do that!

We’ll be using a few tools for this. None of them are all that complicated and these little tools (do one thing and do it well) are tools that make the Linux world go around. 

For starters, we’ll be using the ‘who’ command.

who – show who is logged on

We will also be making use of the ‘awk’ command.

gawk – pattern scanning and processing language

Next, we’ll be using the ‘echo’ command.

echo – display a line of text

There will also be the ‘write’ command.

write — send a message to another user

We will also be using a pipe. We will pipe the output from one command to another command. We’ve done that lots of times on this site, so regular readers will already be familiar with a pipe and how it works.

Briefly speaking, a pipe is just one way to take the output from one command for use in another command. It’s a pretty handy tool to add to your Linux toolbox if you haven’t already done so. It’s a simple tool, which is a good thing.

If all of the above looks complicated, don’t be alarmed. It’s not all that complicated and the commands I share will be simple enough for most anyone to follow. You’ll be able to adjust them to your needs quite easily.

Send A Message To Another Logged In User:

As mentioned in the intro, you’ll want an open terminal for this. So, open your default terminal emulator. You can usually just press CTRL + ALT + T and your default terminal will open. This isn’t always true, but it’s true in many cases. You will otherwise need to open the terminal on your own.

With your terminal now open, let’s find out who is logged in. To do that, we only need the following command:

However, we only care about the first two fields, so let’s narrow that output with the following command:

The output from that command is all we need for the next part. You use the first column to identify the username. That makes them easy to identify, or at least easier for most folks.

The other column is the 2nd one. That identifies their login method, basically which terminal they’re using, and is also what we will use to specify the recipient of our message. Next, to send a message to another logged-in user, you use a command similar to this:

Or, take a look at this:

identify and send a message to a logged in user.
See? It’s not complicated. It’s harder to describe than it is to do.

So, in that case, the syntax of the command is easy, it’s just like this:

You’ll notice that the output of the command isn’t on that screen. It was sent to the other screen, the screen where that user was logged in (specifically over SSH). It quite happily sends the message to the user logged in at that location.

You can’t use usernames alone, as it’s possible for more than one person to use the same username. This method identifies the user and the method/location they’ve used to log in. It’s a pretty handy command like that. It might look a bit complex, but it isn’t.

Closure:

So, if you’ve ever wanted to send a message to another logged-in user, you can now do that. It’s easier done than explained, but hopefully, you get the gist of it and can apply it to your personal computer usage.  

It’s not always that easy to come up with ideas for articles. I often pull them from my notes, but my notes are a mess, and not all of them would make good articles. If there’s something you’d like covered, and I know the subject, feel free to contact me and let me know. Of course, don’t forget that I take guest articles when they’re about Linux.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Add A New Line With CURL

Today’s article isn’t going to be all that long and it’s definitely not going to be complicated, as we just discuss how to add a new line with curl. It’s just an annoyance factor and something I was reminded of today. Lacking a better idea, I decided I’d use this annoyance and recollection as a reason to write an article about how to add a new line with curl.

First, this obviously requires a terminal.

Second, this obviously requires curl. You almost certainly have curl installed, so you won’t have to install anything. 

If you’re curious, you’ll find that the curl man page defines the application as:

curl – transfer a URL

You’ll understand why I’d use that in a second, but you can imagine that it’s a pretty handy tool to have in your Linux toolbox. We’ve previously used curl in many articles. Here’s a sampling of those articles:

Let’s Have a Limited Look at Linux’s cURL Application
Weather In The Terminal? We can do that!
How To: Find Your IP Address Through Your Terminal

… and more!

So, in this case, I show ads on the site. To do this, Google relies on a file known as ‘ads.txt’ being in your web’s root folder (often called ‘public_html’). If the file is not there, there’s an ad inventory issue and Google won’t show ads.

Well, if you read the previous article you’d know that there was an outage. During this outage, it appeared that the site was still reachable – except it wasn’t. It was during this time that AdSense decided to check and see if the ‘ads.txt’ file is there. (This is nothing private. Everyone using AdSense has an ads.txt file.)

Because of this, I decided to verify that the ads.txt file existed and contained the appropriate information. To do this, I simply used the following command:

It gave me the answer I wanted, but I disliked the formatting of the output. But, it was enough for me to determine that the file existed and that I just had to wait for Google to confirm this.

The formatting was horrible. I’ll show you an image in the next section and you’ll see…

Add A New Line With curl:

So, when I saw the output from the above command (feel free to run it on your computer), it just ran the line into the next prompt. I had to dig through my ~/bash_history file because I couldn’t remember how to fix the formatting.

A picture is probably going to describe this best. In the picture, you’ll see the ugly formatting and you’ll see the solution.

adding a new line to the curl output
As you can see, the second command has a much nicer output.

So, to make sure you have a new line, you use the -w (write-out) flag and add the character for a new line in quotes – which is "\n". It’d look like this:

As you can see (and I hit the enter button between commands to start on a fresh new line) the output is much nicer. So, instead of curl starting a new line, a command entry line as it were, you’re starting with a nice fresh new line.

I messed with this way too long before I started digging into my bash history to find other curl commands used over time. Eventually, I found it, but I’d already verified that the file existed and that Google would notice the next time they checked.

Closure:

Well, it’s not the greatest of articles – but it’s useful if you want to know how to add a new line with curl. It’s a much tidier output this way. I just need to remember to do it without having to dig through my bash history each time I want to have a clear curl output.

Meh… I’m sure it’ll eventually be handy for someone…

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Play Around With The Linux Shell.

Today’s article is a bit of a mystery, as I’m writing it and not sure how it’s going to end up – but it will be about the Linux shell. I’ll try to make it approachable, even for beginners. Let’s see where the article takes us!

I think I’d caution most beginners to stick with what came with their distro (most likely Bash), rather than straying into the world of different shells. Wait until you have a few more miles in your Linux shoes before running to try new shells. It’ll make support easier if you don’t have to compound things by using an alternative shell. Once you’re up to speed, there are some nifty choices.

This seemed like the perfect question to pose ChatGPT. I’ve found a way to make AI useful – or so it seems to me. I asked the AI to explain the Linux shell in two paragraphs. This is what they had to say:

A Linux shell is a command-line interface (CLI) program that allows users to interact with the Linux operating system by entering commands. It acts as an intermediary between the user and the kernel, which is the core of the operating system. The shell provides a text-based environment where users can execute various commands to perform tasks such as navigating the file system, running programs, managing processes, and configuring system settings.

The shell interprets the commands entered by the user and translates them into instructions that the kernel can understand and execute. It also provides features like command completion, history, and scripting capabilities, allowing users to automate tasks and create powerful scripts. There are different types of shells available in Linux, such as Bash (Bourne Again SHell), which is the default and most widely used shell in Linux distributions. Other popular shells include Zsh (Z Shell), Ksh (Korn Shell), and Csh (C Shell), each offering its own set of features and functionalities. Overall, the Linux shell is a fundamental component of the operating system, providing users with a flexible and efficient way to interact with the system.

That looks like a pretty good description to me. If you have any questions, you can certainly leave a comment. You know where to find me so that you can ask questions most anywhere.

Hmm… As I said, I’m not sure where this article is headed. We’ll have to see…

Some Stuff About The Linux Shell:

Pretty much every single one of the new folks reading this will have something in common with those who have used Linux for years. You’re almost certainly using Bash as your shell. Bash stands for Bourne Again Shell. Bash is the Linux equivalent of Bourne Shell that came with Unix back in ye olden days.

If you want, you can open a terminal at this point. Odds are that you have another shell or two available. You can list your shells with the following command:

If you don’t already know what shell you’re using, you can find out quickly enough. Just run this command to find out which shell you’re using:

Let’s pretend you’re using Ubuntu and want to install a new shell. Let’s pretend you are interested in ZSH. That is ‘Z Shell’ and is an alternative that you might consider. The first step would be to install ZSH and you’d do so like this:

Follow the prompts and when you next run cat /etc/shells again, you’ll see that ZSH is an option. Pay attention to the path. It will look like /usr/bin/zsh and you can change to that shell quickly enough. Just run the following command:

Or, for a better example:

You’ll then want to reboot your system. That’s easily done with:

That should do the trick for pretty much everyone, though you’ll need to use your package manager if you’re not using apt with Debian, Ubuntu, Mate, or similar. It’s easy enough to switch to a new Linux shell – but you should probably have a good reason for doing so.

By the way, feel free to leave a comment if you use a different shell, preferably explaining why you’ve chosen to do so. I’ve played with different shells and that was entirely my reason for doing so, I just wanted to play around with them. I stick with Bash pretty much exclusively, or whatever’s installed by default.

Again, I’d caution you newer users to skip this article and just use this pile of words to learn about shells in the first place. If you’ve been using Linux for a while and want to learn something new (or have a specific reason to do so) then you can change your shell as much as you’d like. It’s your computer, you can do anything you darned well want with it!

Closure:

So, I wasn’t sure what this article was going to look like. I just figured I’d do an article about the Linux shell. We all know at least one beginner is going to start mucking about with alternative shells, at least this way we can tell them that we suggested they wait to do so.

Then again, how often did we wait to do so? How often did we go mucking around with things best left untouched until we learned better? At the end of the day, Linux is an OS that suits those who like to tinker, but she can be a harsh mistress when you’re still learning. And, again, how many of us learned by breaking things? I reckon many of us did and that’s how we got here.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Use Tab Autocomplete In The Linux Terminal

Today’s article isn’t all that complex or anything, we’ll just cover how to use tab autocomplete in the Linux terminal. It’s a pretty handy tool to have in your Linux toolbox. It’s especially handy if you spend a lot of time in the terminal.

It seems to me that tab autocomplete is easier to do than it is to explain. It’s a great concept. I asked ChatGPT to explain it on my behalf and it did a fairly good job. It’s the middle of the night and I almost forgot to do an article. I got distracted, ended up elsewhere in the house, and fell asleep.

Fortunately, I already had the headline written. (Coming up with ideas is often more time-consuming than writing some articles.) That was a good thing. Otherwise, I’d have gone back to sleep and just written this tomorrow.

Anyhow, tab autocomplete is a tool that WILL save you some time. If you were local to me, it’d take like 2 minutes to show you how autocomplete works. It’s gonna take a bit longer to explain it with text!

I suppose that’s an adequate intro. Let’s see how AI does at explaining tab autocomplete and then try to make it more clear below that:

Use Tab Autocomplete In The Linux Terminal:

Linux terminal tab autocomplete is a feature that allows users to quickly and efficiently navigate through the file system and execute commands without typing out the entire file or command name. It works by automatically completing a partially typed file or command name when the user presses the “Tab” key.

To use tab autocomplete, the user needs to start typing the file or command name in the terminal window and then press the “Tab” key. If there is only one file or command that matches the typed characters, the system will automatically complete the name. If there are multiple matches, the system will display a list of possible options. The user can then continue typing until the desired file or command is highlighted and press “Tab” again to complete the name.

Tab autocomplete can be used for a variety of tasks, such as navigating the file system, running programs, and passing arguments to commands. For example, if the user wants to navigate to a directory called “Documents” in their home directory, they can type “cd Doc” and press “Tab.” The system will automatically complete the name to “cd Documents/”. This can save the user time and effort compared to typing out the full path.

Tab autocomplete also supports wildcards, which can be used to match multiple files or commands with similar names. For example, if the user types “ls *.txt” and presses “Tab,” the system will show a list of all the files in the current directory that end in “.txt”.

In summary, Linux terminal tab autocomplete is a powerful feature that allows users to quickly and efficiently navigate the file system and execute commands without typing out the entire name. It saves time and effort and can be used for a wide range of tasks.

Additional Tab Autocomplete Stuff:

So, to put that information to use, we can open a terminal. You can do so now just by pressing CTRL + ALT + T.

With your terminal now open, try the following command:

Now, press the TAB key on your keyboard (you may need to press the tab key twice). You’ll see something like this:

use tab autocomplete in the Linux terminal
You can probably figure it out from here. Once you understand it, you’ll appreciate it.

As you can see, it was not able to autocomplete because there were two available choices. If there are no choices it will show nothing. In this case, if you want to change to the Downloads directory, you’d enter the following:

Press the TAB key (probably twice), of course. For most of you, that’ll be enough. If it’s not, you should be able to figure out the minimum number of characters needed for autocomplete to work.

This also works on commands, but you need to have narrowed it down or it needs to not start with the more common letters. How to explain it?

If you type ‘l’ and hit tab, nothing will autocomplete.

If you type ‘ali’ and hit tab, it will spot autocomplete to ‘alias’. Additionally, it works for your installed applications. If you just enter ‘l’ and press the tab key (twice, if once doesn’t work) it will offer to display a bunch of commands starting with the letter ‘l’. For many of you, you should be able to just type ‘pav’ and then press the tab key to have it autocomplete to ‘pavucontrol’. That should make it reasonably clear.

Closure:

See? It’s not hard to do. It’s easier to do than it is to explain. I’ve never really needed to properly explain tab autocomplete in text format before. It’s much easier just to physically show folks than it is to explain it in text. Hmm… Now I can go back to bed. Dunno if I’ll sleep again, but I might as well try.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Not Save A Command To Bash History

Today’s article is another short-form article, where the subject is how to not save a command to bash history. It’s trivially easy and something everyone can learn. So, read on and learn how to not save a command to Bash history.

The vast majority of my readers are going to default to using Bash. 

bash – GNU Bourne-Again SHell

You’ll access Bash through your terminal and, again as the default, will save x-amount of past commands to a file known as ~/.bash_history. Anything you enter as a command (though not passwords entered at the password prompt, as that’d just be silly) will be saved to that file.

If you’re like me, you use the terminal a great deal. Again, if you’re like me, you value the Bash history aspect but you don’t want it full of trivial or experimental nonsense. You can prevent a terminal input from being saved in your ~/.bash_history – and it’s trivial to do so.

Do Not Save A Command To Bash History:

Seeing as I’ve been doing short-form articles for the past couple, this one seemed like a lovely tip to share with my readers, as I’m sure some will not know this. 

Of course, you’ll need an open terminal for this. Press CTRL + ALT + T and your default terminal should open.

With your terminal now open, we’ll use the ‘ls’ command to list the contents of your present working directory. Ready?

Now, that’ll be saved to your Bash history file. What if you don’t want it saved to that file? Just add a space in front of it, like so:

I don’t know how well that will show up, but trust me when I say there’s a space there. By adding that space, I’ve effectively told the terminal to not save that entry into the history file.

See? Pretty darned simple!

Closure:

So, yeah… I’ve been doing a few short articles and this seemed like the perfect article to do in that format. It’s something not everyone knows, isn’t made immediately obvious, and will likely be of importance to someone. If you’ve ever wanted to not save a command to bash history, that’d be how you do it.

I could have added a few more bash tricks and turned this into a longer article, but I’m having fun with this shorter stuff right now. If you prefer the longer articles, don’t worry. They’ll be back soon enough. These short articles are fun and easy, and they have the added benefit of keeping me interested in writing these silly things.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment. 

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.