Every operating system, whether being used as a personal computer or as a server, maintains a log of the shutdown, reboot, and login times. This is not only important for system administration, but also for troubleshooting problems.
In Linux, all logs are stored in the ‘/var/log/’
directory. The details about logged-in users and respective shutdown, reboot, and login times are also stored here.
Let’s see how we can find out the last reboot date and time on your Ubuntu system.
Using Last Command
We can run the command last with the parameter ‘reboot’ to get the time and date of the last reboot.
last reboot
As seen below, the list of last reboots is displayed. To just display the latest reboot, filter the output with the ‘head‘ command.
last reboot | head -1
Using Who Command
The who command in Linux displays information about the logged-in user.
who
As shown below, it displays the logged-in user name, the ID (:0)
, the login time, and the remote or local display ID (:0)
.
If we execute this command with the '-b'
flag, it displays the time and date of the last reboot.
who -b
Using Uptime Command
The uptime command displays the uptime of the system, i.e., how long has the system been running. It outputs in the length of time the system has been running.
uptime
We can pass the argument '-s'
to output the last time the system was booted.
uptime -s
Users can also pass an argument '--since'
which gives the same result as '-s'
.
Using journalctl Command
You can also check detailed system logs for more information about the reboot using the journalctl command as shown.
journalctl --list-boots
This will show a list of recent boots. For more detailed logs for a specific boot, you can use:
journalctl -b <boot_id>
Conclusion
In this article, we looked at the ways of finding the last reboot time in Ubuntu. Apart from simply viewing the time, an advanced user/administrator can also make use of the output of the above commands in a script.
If you have any questions or feedback, make sure you leave a comment below!