Get Exact Boot, Sleep, and Wake Times from the Command Line
Need to know exactly when your Mac was last booted, put to sleep, or woke from sleep? You can get precise information about boot and sleep times directly from the command line, which can be invaluable for anything from troubleshooting various Mac problems to scheduling scripts, or even for your own forensic purposes to determine when a computer was last used.
Each of these command strings requires input into the Terminal, that application can be found in /Applications/Utilities/ or launched from Spotlight or Launchpad. We’ll assume you have some experience with the command line, though copying and pasting the command strings will work just fine.
Get Precise System Boot Time
Enter the following command string:
sysctl -a |grep kern.boottime
The results will look something like this:
kern.boottime = Mon Jul 4 08:00:42 2011
If you’re looking for a record of a Macs boot history, try using the “last reboot” command instead. Similarly if you’re only looking to see how long a Mac has been powered on, you can use the simple “uptime” command, which will give you the lapsed time since last system boot.
Get Mac System Sleep Time
The following command syntax will provide the sleep time;
sysctl -a |grep sleeptime
Resulting in something like:
kern.sleeptime: { sec = 1310538756, usec = 323918 } Tue Jul 12 23:32:36 2011
Get Mac OS X System Wake Time
Wondering when the Mac was last woken from sleep? Use this command string instead:
sysctl -a |grep waketime
Results will resemble this:
kern.waketime: { sec = 1310573055, usec = 11 } Wed Jul 13 09:04:15 2011
Don’t forget that you can also find out why a Mac woke from sleep by reviewing system logs and interpreting the reason codes. All of this information can be helpful for troubleshooting, and also used for forensic purposes to determine when a computer was used and put to sleep, though like all digital data, it may not be considered reliable enough for all purposes.
You can skip the grep portion:
sysctl kern.boottime
sysctl kern.sleeptime
sysctl kern.waketime
or to get just the value:
sysctl -n kern.boottime
sysctl -n kern.sleeptime
sysctl -n kern.waketime
@Curtis and @Sean, it’s not that much of a WTF. Jan 1 1970 00:00 is known as the Epoch in Unix – the “start” of unix time. It has the integer value 0. If the value for sleeptime was unset it was probably left at 0 (or NULL – basically the same). The fact that you have a time a few hours earlier than this is probably just due to time zone peculiarities.
You gave them the problem, how about a solution? How do i get correct time my mac went to sleep?
@Sean-My computer says that too. I do notice that my computer does not sleep on its own. In fact, the only way to get it to sleep is to close the lid, or manually.
kern.sleeptime: { sec = 0, usec = 0 } Wed Dec 31 16:00:00 1969
kern.waketime: { sec = 0, usec = 0 } Wed Dec 31 16:00:00 1969
I whole heartedly agree WTF?!?!?!
Something wrong here, this is the result I get from asking about my wake time:
kern.waketime: { sec = 0, usec = 0 } Wed Dec 31 16:00:00 1969
1969??? WTF?
Well, and what means “sec = 1310538756, usec = 323918”??
I used a similar tip to discover that my cat had been walking across my keyboard at precisely 3:48am each morning and waking up my iMac. Determined to outwit the feline, I placed a large sheet of tinfoil over the keyboard. It hasn’t happened since. Add that to your tip sheet.