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

Jul 14, 2011 - 4 Comments

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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

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

4 Comments

» Comments RSS Feed

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

  2. Alberto says:

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

  3. 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?

  4. 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?!?!?!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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