How to Check Last Reboot Time on Linux

How to Check Last Reboot Time on Linux

Ever wondered how to check last reboot time on Linux OS? Here’s how you can find out all about it. 

At times, you have several questions about the users and the time since the last reboot. Some of these questions may be as follows:

  • When was the last time system rebooted, i.e., the exact time
  • How long has the system been running (number of hours and days since the last reboot)
  • The list of users who are logged in the current system

This article attempts to answer the above questions. We will specifically discuss the following four methods to determine the last reboot time: who, last, uptime, and dmesg.

Why would one like to know the last reboot time?

It is important to answer why one would like to know the last reboot time. There can be multiple reasons. Some of them are:

  • You would like to troubleshoot a problem in your system
  • You would like to track any event, such as a hacking attempt
  • You may want to know how often your system boots

The who command

The first command that we will discuss is the “who” command. The who command is installed by default in Linux. It can be used to print the information about who has logged in and the last system boot time. We will now discuss the usage of who command.

Usage of the who command

To use the who command, open your Terminal and type the following command:


This will display the information about the currently logged-in user. To find the time since the last reboot, use the following command:

$who –b

The above command uses the –b flag and displays the information about the last boot time. The command will display information such as:

system boot  2019-04-08 11:08
system boot  2019-04-08 11:08

Other options of who command

There is a range of other options for who command, such as:

  • Use option m and H to display the name of the host and devices associated with the user
  • Use option a to display the details of each logged-in user
  • Use option q to count the number of logged in user
  • Other options such as p, T, and u are available, and manuals can be consulted for details

Last command

Similar to who command, the last command can also be used to display the list of the logged-in users and the corresponding boot times. It basically checks the list of logged-in users since the file /var/log/wtmp was created. Following are the various ways in which you can use this command:

  • You can list the sessions of a specified user, tty, and host
  • List down the users logged in on a specified date or time

Usage of the last command

As discussed above, the last command can be used to find out the list of the last logged-in user and the last reboot time/date. For this purpose, type the following command on your Terminal:

$last reboot | less
$last reboot | less

You can also use the head command as a pager as well, i.e.,

$last reboot | head -1

For finding the last shutdown time and date, use the following command:

$last -x| grep shutdown | head -1

Note: In the above command, the –x command shows the shutdown entries and run level changes, while the shutdown and reboot act as a filter.

How to Check Last Reboot Time on Linux using the last command

If you want to find the exact time elapsed since the last reboot instead of the time at which the reboot takes place, you can try the following script:

seconds=$(cut -d. -f1 /proc/uptime); echo System booted $((seconds/86400))" days "$(date -d "1970-01-01 + $seconds seconds" "+%H hours %M minutes %S seconds ago

Uptime command

The third command that we will study is uptime command. The uptime command can be used the check the last reboot time in Linux. It can be used to determine how long the system has been running. In addition, it displays the time since the last reboot time.

Usage of uptime command

To use the uptime command, type the following on your Terminal:

# uptime –s

It will show the time since the last system reboot.

Finding the time of the last reboot using the uptime command

The uptime command shows the total hours and days since the last system reboot. However, if you want to calculate exactly the time since the last system reboot, the following Perl script can be used.

uptime | \
perl -ne '/.*up +(?:(\d+) days?,? +)?(\d+):(\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
$now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'

Dmesg command

The last command is dmesg. The dmesg can also be used to determine the last boot time. Basically, the command is used to print and control the kernel ring buffer. 

Note: Kernel ring buffer is a kernel data structure that stores information about kernel activity.

Usage of dmesg

To view the last reboot time with dmesg, type the following command on the Terminal:

$dmesg | grep “systemd-” | head -n 20

The above command will show the last 20 lines containing systemd.

In this article, we have discussed the various ways to find out the last reboot time in Linux. We discussed four ways, i.e., who, last, uptime, and dmesg. Using these commands, we can find the details about the last reboot and the list of logged-in users. These commands can be used to troubleshoot various problems in Linux. We discussed only the basic options of these commands. There are a host of other options available with these commands. For more details, manuals can be consulted.

If this guide helped you, please share it.

Leave a Reply
Related Posts