In this Linux quick time we will discuss several commands to find your Linux systems last boot time. As an added bonus, we will show you how to find how long it has been since last reboot. Yes, there is a difference, you can find either the last reboot date and time (i.e. 12 SEP 2019 11:40:11) , or how long ago it rebooted (i.e. 4 days, 6 hours, 3 minutes and 22 seconds ago).
Find Reboot Time Using the "who" Command
The who command is part of the GNU Core Utilities. People often associate this command with checking who is logged into a system. However, it does a lot more than just print logged in users. With the -b (--boot) option you can quickly get the date and time of the last system boot.
[savona@putor ~]$ who -b system boot 2019-10-26 11:40
Find Reboot Time Using the "last" Command
The last command is also usually associated with information on users. People often uses this command to see the last users who have logged in. Linux systems have a "special user" named reboot who log in when the systems reboots. We can use last and a couple of options to check for that date and time.
[savona@putor ~]$ last reboot -1 reboot system boot 5.3.5-200.fc30.x Sat Oct 26 11:40 still running wtmp begins Tue Apr 3 16:19:28 2018
How Long Since Last Reboot?
We know that /proc/uptime holds the number of seconds a system has been up. The first field of numbers in this file represent how many seconds ago the last reboot happened. We can take those seconds and convert them to days, hours, minutes and seconds.
What makes this method unique is that it tells you how long ago the system booted instead of the date and time of the last boot. This could be handy in scripting if you want a more human friendly representation of the last reboot time.
[savona@putor ~]$ 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") System booted 0 days 11 hours 48 minutes 59 seconds ago
Sometimes it's fun (and a healthy way to learn) to do something just because you can. If you are like me, you just checked the /proc/uptime file on your system. Just as an FYI, the second field of numbers in that file are the amount of time each core has spent idle.
Conclusion
There you have it, several ways and formats to show the last reboot time of your Linux system. I am sure there are other interesting ways to find this out. If you know of any, feel free to sound off in the comments.
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)