Get Exact Boot, Sleep, and Wake Times from the Command Line

Jul 14, 2011 - 7 Comments

Terminal in macOS

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.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Troubleshooting

7 Comments

» Comments RSS Feed

  1. Joe says:

    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

  2. Carl-Erik Kopseng says:

    @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.

  3. Curtis says:

    @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?!?!?!

  4. Sean says:

    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?

  5. Alberto says:

    Well, and what means “sec = 1310538756, usec = 323918”??

  6. Derpus says:

    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.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site