Linux: Finding out last reboot time (different approaches)📄 BetterWays.dev wiki page | 🕑 Last updated: Feb 18, 2023
There are a few ways to find out when the Linux system was rebooted last time.
The first one is by using the data on the current boot stored in
/run/utmp) file. Since the data is stored in a binary format, we can't access it directly, but we can use the
who -a, you should see a lot of data on the current boot:
system boot 2020-11-24 11:07 run-level 5 2020-11-24 11:07 LOGIN tty1 2020-11-24 11:08 679 id=tty1 LOGIN ttyS0 2020-11-24 11:08 678 id=tyS0 ...
Since we're interested only in time of the last system boot (the first line), we can limit the output with
-b switch (shorthand for
system boot 2020-11-24 11:07
Alternatively, we can use the data from
/proc/uptime, which contains the number of seconds since the system has been up.
We can either read and parse the
/proc/uptime file directly, or use the
uptime command, which by default returns output like this:
22:24:11 up 817 days, 11:16, ...
More info on this approach: Linux: Finding out uptime of the system by reading ∕proc∕uptime
There's also the
/var/log/wtmp file which contains historical
utmp data. As with
utmp, it's a binary file, so we can't read it directly, but we can use the
If we execute
last reboot, we may get something like this:
reboot system boot 4.19.0-12-amd64 Tue Nov 24 11:07 still running wtmp begins Sun Nov 1 05:37:31 2020
The problem with this method is that
wtmp file may get rotated, so we may get partial data. Generally,
utmp are better methods to find out this information.
Ask me anything / Suggestions
If you find this site useful in any way, please consider donating. I'm trying to keep it as clean and fast as possible - there are no ads, no affiliate links, and no analytics/tracking scripts.