Getting date and time of system startup in Linux
I found some commands here. Try who -b
or last reboot | head -1
.
who
gives numeric dates, while last reboot
returns abbreviated day / month names.
This queries the uptime from the kernel and displays it in the local timezone:
date -d "`cut -f1 -d. /proc/uptime` seconds ago"
Be careful about other options. The last
command will stop working as soon as wtmp
has been rotated. The who
command depends on the availability and integrity of utmp
. And /proc/1
might have the current date instead of the boot time date, and could even be unavailable on a hardened system. Edit: dmesg
only has a fixed-length back buffer, so it is unrealiable, too. The kernel logs may be in /var/log
but most distributions only keep 8 weeks of them.
I stumbled on this question while looking for a way to get a consistent, parseable boot time, as opposed to time since boot which changes on every call.
It appears that uptime -s
will do the trick on most linux systems.