How to Find the System Restarted Time in Linux

Overview: Using the last, who, and uptime commands in Linux, you can find out when the system was last turned off and on again. Please click here to go straight to the command reference.

Hey, Could you please tell me how to find out when my Linux or Ubuntu system restarted? As you know, we keep the system running for several days or a month without giving it a rest.

Yes, I get your point, so don’t worry. I’ll show you how to find out the exact date and time your system last rebooted. Not only this, but you will also know when was the last time the system was shut down.

Sounds cool, right? Then let me get you to the arena where you will learn how to use last, who, and uptime commands to find the last system shutdown and restarted time in any Linux distribution.

How to Find System Restarted Time in Ubuntu

Thanks to the log stored in "/var/log", from which you can easily find out when the last system rebooted, shut down, and much other information from the respective directory, you don’t need to run around this directory to just find all this information because we have a command for this purpose to draw the data meaningfully.

So, first, start with the last command

Using the last Command

By default, the last command uses the /var/log/wtmp file to read the system information to find and print out the last reboot, shutdown, and other crucial information on the terminal screen.

Using the last Command to find reboot

When you run the last command on your terminal, it will show you something similar to the below image, which may seem overwhelming to understand but is actually pretty easy to understand once you look at the output thoroughly.

last command
Output: last command

According to output, you can find the last system reboot occurred on January 2 at 09:43, which is currently running, and if you go further, you will find my system was restarted multiple times on January 1.

To get more accurate information, you can suppress another user by just passing the username.

At this point we are interested in finding the system reboot information, so you can just pass the argument reboot, which is the pseudo user that has stored the system reboot information since the log file was created.

$ last reboot

This is the result of running the above command:

Output: last reboot command
Output: last reboot command

The above output looks much better, but if you can show me the last reboot date and time, then it will make much more sense to me.

For this purpose, you can pipe the output to the head command, which will just print the first line of the statement while suppressing other data.

$ last reboot | head -1

This is the result of running the above command:

Output: last command pipe with head
Output: last command pipe with head

Using the “last” Command to find shutdown

The last command can also be used to find the shutdown date and time as well as when the system was turned on. You already know how to find the last system restart time, so now it’s time to find the shutdown time.

To find out when the computer shut down, you need to use the -x or --system option to tell the last command to add shutdown and runlevel information to the default output.

After that we will pipe out the default output to grep command to filter out the result.

last -x | grep "shutdown"

This is the result of running the above command:

Output: last command print shutdown date and time
Output: last command print shutdown date and time

And to find out about the last time the computer was shut down, you can type the following command into your terminal window.

$ last -x | grep "shutdown" | head -1

Using the “who” Command

The next command is the who command, which you have already used. If you have read our article on who has logged into my Linux system, then you may already be familiar with the who command, but for those who are hearing about it for the first time, it is a simple command that displays who is logged in.

To find the last system boot using the who command, you need to append the -b or --boot option, like in the below code snippet.

$ who -b
or
$ who --boot

Without using pipegrep, and head, the above command’s output is much less complicated and easier to read.

Output: who command to find last system boot
Output: who command to find last system boot

Using the uptime Command

Similarly, you can use the uptime command to find the last system boot. You need to replace the command name and the option to display boot time.

If your terminal is up, then run the below-mentioned command to find the last boot date and time.

$ uptime -s
or
$ uptime --since

The results are extremely simplistic, consisting solely of the date and time. This command will be beneficial if you’re planning to use it in a bash script to find the last system boot date and time.

Output: uptime command to print last system boot
Output: uptime command to print last system boot

Cheat sheet for finding system boot time

  • To find the reboot information since the inception of the log file, use the last command
    • $ last reboot
  • To find the most recent reboot information, use the last command
    • $ last reboot | head -1
  • To find the last system boot date and time by using the who command
    • $ who -b
  • To find the last system boot date and time without any extra data, use the uptime command
    • $ uptime -s

Wrap up

After reading this article, you will be able to quickly determine the system’s last reboot and shut down time. If you know of any other means to find this information, don’t forget to drop that information below.

Put your feet up and relax. As always, the next article will be up shortly.

Leave a Reply