Find Your Last Boot Time In Linux

It’s a weekend so today’s article will be short and easy, an article for when you want to find your last boot time in Linux. If you want to know when you last booted your computer, there are many ways to get that information. We’ll just cover one way…

We’ve covered a couple of ways to do this in the past. If you want, you can read the following article:

When Did I Last Reboot My Linux Box?

I wrote that article more than two years ago. It was one of my earliest articles. In that article, I covered a couple of different ways that you can find out when you last rebooted your Linux computer. 

In that article, we covered commands like:

There are some advanced commands you can use, so do read the previous article to learn more about how you can find your last reboot time.

In that article, I also mentioned that you could see how long your computer has been on since the last reboot with the uptime command. That’s simply done:

Speaking of the uptime command:

How To: Find Your Uptime In Linux
The Meaning Of “Load Average” On Linux?

Those articles might be of interest. This is a simple article, but it does allow you to read quite a bit more related content.

Find Your Last Boot Time In Linux:

You guessed it. We’ll be doing this in the terminal. That means you’ll need an open terminal. If you’re not sure how to do that, look in your application menu or press CTRL + ALT + T and your default terminal should open.

For this article, we’ll be using the who command. You can check the man page with man who to learn more about the command. If you do that, you’ll learn that the who command is described as:

who – show who is logged on

That may not be as descriptive as it could be. If you just run the following command, you’ll be able to see everyone who is currently logged into your system. That’s just this command:

That simply tells you who is logged in. Your output might look a little like this:

As you can see, I am logged in both on tty7 (the desktop) and tty3.

If you did check the man page, you’d have possibly seen the -b flag. That flag is described accurately:

-b, –boot
time of last system boot

See? Now it should be obvious why I’ve chosen to write this article about how you can find your last boot time with the who command. The command is simply:

Which will output something similar to this:

See? That’s all you need to know if you want to find your last boot time! It’s not all that difficult to get started with the Linux terminal. This is a command any Linux user can learn. It’s also a pretty easy man page to decipher. So, that’d be good for new users as well!

Closure:

It’s a weekend and I’m lazy today. So, you have an easy article. It doesn’t have to be all that easy. I gave you plenty of links that you can (re)visit. Visiting those links will also show you how much the site has changed – specifically with how I write the articles. This particular article is a lot like how I wrote many of the articles, but I’ve been mixing it up quite a bit. I was just really in the mood for an easy article today, so you got this one about using the who command to show when you last rebooted your system.

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.

Yet Another Way To Find Files By Extension

You might look at the title and think that you’ve seen this before, and you have, but this is another way to find files by extension. That’s right! This is Linux! There’s almost always a variety of ways to think about this. There are almost always a variety of ways to accomplish the same task!

Well, this article will touch on a theme we’ve seen before. We’ve seen it recently. I’ve even explained why you might want to find files by their extension type. Fortunately, I’ve even explained the limitations this has.

See a shell script file could have a .txt extension but still work just fine as a script. Linux cares about the file itself more than it cares about the extension. If you have files mislabeled as an .iso file, this operation will still list them as .iso files. This is only about the extension and using that as a search category. It has limitations.

You can read these articles for more:

Another Way To Locate Files By Extension
Find Multiple Filenames By Extension – With Locate
How To: Find Multiple Filenames By Extension

See? It might seem that this article is like beating a dead horse, but it’s not. There are use cases for all of these options, including the option I’ll give you in this article.

Also, it seems like a good day to take it easy. Life has sent me a bit of extra stress. That won’t stop me from writing this article. It seems nothing will stop me from writing these articles!

The ‘ls’ Command:

This is kind of the sledgehammer way to find files by their extension. It’s a good way. It’s even an easy way to remember, without needing extra commands. At the same time, it’s a pretty basic way to do so.

The first command we’ll work with is one you have installed already. You won’t need to add any software to follow along with this article. We’re simply going to use the ls command to list directory contents. 

If you check the man page for the ls command, you’ll see this:

ls – list directory contents

What did I say in the paragraph before that? I said we’re going to list directory contents. Sure enough, Linux provides the perfect tool for this. 

As an aside, what you can accomplish with a basic Linux install is amazing. You can accomplish a whole lot of work without actually adding any additional software. This is awesome. Thank you, Linux.

The ‘grep’ Command:

The second command we’ll be using is the grep command. If you’re a regular on this site, you’ll have used the grep command many times. You can think of the grep command as a filter. You use the grep command to process the output of another command (more often than not) and, more specifically, you use it to filter that output.

You want to use grep when you’re trying to isolate some information. Well, sure enough, we can check the man page for grep. If you do so, you’ll find that grep accurately describes itself like this:

grep, egrep, fgrep, rgrep – print lines that match patterns

You’ll see that grep comes in many forms. You’ll also see that it’s used to print lines that match patterns. The command is filtering out those lines that don’t match the prescribed pattern.

In fact, I used it as an example in the previous article:

Find Out When A File Was Created

Scroll down to see how you can use the grep command to filter out the lines that aren’t important when you simply want to find out when a file was created. Simple, eh? Yes… Simple!

Find Files By Extension:

As you can guess, we’ll be using both the ‘ls’ command and the ‘grep’ command to find files by extension. As those are terminal-based commands, this will be a terminal-based article. You’ll need to open a terminal and you can (more often than not) do so by pressing CTRL + ALT + T.

With your terminal now open, this is the syntax I want you to use for this exercise. We’ll keep it simple:

If you’ve used mix-case, maybe having extensions of .TXT (in capital letters), you can add the -i flag to the grep command. That will (don’t forget to check the man page) tell the grep command to ignore the case. So, an example of the syntax for that command might be:

For example, I might want to search my ~/Downloads directory for .iso files, finding the various distros I’ve downloaded on this computer. If I wanted to do that, my command would look like this:

And, sure enough, here’s an example output from that very command:

See? That output shows you all the .iso files that I have in my ~/Downloads directory. There’s no fuss. There’s no muss. It’s just a simple way to find files by extension.

Anyone can do it and they won’t need any additional software to do so. Everyone (except maybe someone with a very light embedded Linux system – and probably still them) can find files by extension without adding anything to their system. It’s maybe a bit creative, but it’s effective. I’m not sure about you, but I like effective things. This meets that definition squarely – it’s effective.

Closure:

Well, I guess this is still a fairly long article. I’ve been making them longer and this one just got written that way. My style of longer writing isn’t without thought. I have altered the format of these articles a half-dozen times.

Each time I do so, I do so for you. The goal of altering the format is to make it easier for you to digest and to offer more information than previous articles – even for the more basic articles like this one. I do not know if I’ll settle on this style. Evidence would suggest that I’ll improve upon it as I go.

I welcome feedback on this. I don’t suppose you’ll give me that feedback. The odds are good that you won’t even read this far down. Still, please let me know if you like the current writing style. I’ve consistently written to a formula, but that formula has changed over time. This is the most recent iteration, so please let me know what you think. Thanks!

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.

Send A Message To Logged In Users

Today’s article will have limited use for my regular readers, as we talk about how you can send a message to logged-in users. The thing is, this is only valid for those users who are logged into the terminal. It doesn’t pop up a handy GUI window (like the old messenger service from Windows, though I’m sure there’s a way to do so). This is only valid for users who have logged into the terminal.

Got it?

Good!

So, who is this useful for? Well, those of you who have shell users. This is useful for system admins who want to send mass messages to the people who are currently logged in. For example, maybe you want to message folks to let them know that you’ll be doing routine maintenance and rebooting the system at a specific time.

While this is a bit archaic, it’s still useful under some circumstances.

Why do I include it if it’s so archaic and has limited use?

Well, because I can. You never know when someone doesn’t know something and will hit up their favorite search engine to learn something. I care that each article teaches you something, even if that something isn’t all that grandiose. 

Plus, it’s nice to have an easy article now and then. This is going to be a pretty easy article! There are just a couple of tips that I have for folks and that’s the end of it.

Send A Message To Logged In Users:

You’ll need an open terminal if the opening wasn’t descriptive enough. After all, we’re sending messages to users who are logged in with the terminal. So, open said terminal. Most often, you can press CTRL + ALT + T and your default terminal should open.

With your terminal open, you can be reasonably sure that the wall command is available. Run this command to be certain that the wall command is available:

You can then check the man page to ensure that this is the correct tool for the job. As you’ll see, if you run man wall, this is the tool for the job:

wall – write a message to all users

See? It is the right tool for the job. The syntax is even remarkably simple:

Or, if you do this often and want consistency:

So, you can try something like:

Or, if you do this often, you can make a .txt file with your message and just reference that file in the wall command. That’d look like the above example.

See? That’s it. That’s all you need to know to send a message to logged in users. If you’re new to your admin job or maybe have started running a public-access shell, you’re now able to send those messages to your users.

Closure:

I figured it was a good day for a nice easy article. They can’t all be complicated, because not everything is complicated. Sometimes, it doesn’t take 1000+ words to describe a task. I could probably bloviate and digress, but that’d just make the article longer with no real value.

As much as it might seem otherwise, I value your time. I try to remain on topic and I try to include no more than the information you need – with just a bit of digression in the intro. I figure most of you skip the intro anyhow!

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.

Compare Two Text Files Side By Side

Today’s article has a theme that may seem familiar, as I recently wrote an article about how to compare two text files side by side. That article was well received and I figured I’d share another way to compare two text files side by side. After all, this is Linux and there are usually many paths to the same destination.

You can use a variety of tools to compare files. It’s not hard to check two files to see the differences between them. However, you can visually compare them quite easily. All you need to do is to show those two files in a side-by-side manner.

The previous article can be read here:

Show Two Text Files Side By Side

So, that’s one way to show two text files side by side. This article is going to show you another way. Why? Because I can! Also, I’d like to write this article while it’s still fresh in my memory. If I don’t write it soon, I’ll have forgotten to write it at all. Age will do that to a person. It is what it is.

Preparation:

In the previous article, I had you download two files. I’m going to suggest that you do so again. That way, we’re on the same page. 

Download these two files to your ~/Documents directory:

File One
File Two

Those two files should be the same in every way. Byte for byte, they should be the same (with maybe a slight difference in metadata like last accessed time).

The tool we’ll be using is sdiff and you almost certainly have this installed by default. It’s part of the diff tools, so it is likely installed by default. You can verify that sdiff is previously installed with the following command:

 The output should show you that sdiff is just a part of the diff utilities. It should say something similar to this:

sdiff (GNU diffutils) 3.8

Those are the only tools you’ll need. Well, that and a terminal emulator of your choosing. It’ll be easy enough for anyone to follow along with this article.

Compare Two Text Files Side By Side:

As I mentioned above, you’ll need an open terminal. For most distros, you can just press CTRL + ALT + T and your default terminal emulator should open. If not, open a terminal from your application menu.

If you followed the above directions and downloaded the two files, you will first need to change your directory to your ~/Documents directory. That’s easily done with this command:

Then, you can simply compare the two files. The syntax is like this:

So, in this case, the command would look like this:

As you can see the files are the same.

using sdiff to compare two text files side by side
See? The files are the same. You can use sdiff to compare two text files side by side.

Let’s mix things up…

Change One File:

We already have the terminal open, so let’s see this sdiff in action with a changed file. Let’s edit the sort1.txt file with Nano. Run this command:

Now, scroll to the bottom and add the following line:

Then, you need to save the updated sort1.txt file. As we’re using Nano, you can do that by pressing CTRL + X, then Y, and then ENTER. It’s not hard to save a file in Nano.

Now, let’s run the sdiff command a second time so that we can compare two different text files side by side. 

You’ll see a different output. It should look like this:

comparing two different files with sdiff
You can see that one line is different when you compare the two text files.

The > character indicates that there’s a difference. Specifically, it indicates that there’s a new line that isn’t in the first text file. 

On the other hand…

comparing two files with sdiff and one has a different line
This time, the sdiff command is showing two different text files side by side.

The | character shows that the lines are different. This is a different character that shows that there’s a new line. Instead, this one is indicating that the text on that line is different than the file it is being compared with.

See? Pretty simple stuff!

Closure:

Well, this is another way to compare two text files side by side in the Linux terminal. There are so many ways to accomplish a goal in Linux and this is just another way that you can do this operation on text files. This sort of stuff would be handy in dealing with revisions or easily spotting differences in readme files. You can apply this skill to all sorts of situations. Feel free to comment telling me how you use the sdiff command.

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.