How can a I get the total uptime since boot (excluding the sleep time)?
I can use the
uptime command which shows how long since the last boot, but this does not differentiate between active use and sleep or hibernation.
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
As far as I know there is no simple command executed in Terminal to get your desired result.
Here is an example for a workaround to get the uptime and the sleep time(s):
uptime && pmset -g log|grep 'date'|grep -E ' Wake | Sleep '|grep -v 'Dark Wake'
with date: dd/mm/yy (example: 23/07/15)
Example (10.9.5 Virtual Machine):
machinename:~ user$ uptime && pmset -g log|grep '23/07/15'|grep -E ' Wake | Sleep '|grep -v 'Dark Wake' 14:59 up 1:09, 3 users, load averages: 0.58 0.47 0.51 23/07/15 13:51:39 GMT+2 Sleep Software Sleep pid=90: Using AC 10 secs 23/07/15 13:51:49 GMT+2 Wake Wake [CDNVA] due to power-button/User: Using AC 149 secs 23/07/15 13:54:18 GMT+2 Sleep Software Sleep pid=90: Using AC 91 secs 23/07/15 13:55:49 GMT+2 Wake Wake [CDNVA] due to power-button/User: Using AC 1872 secs 23/07/15 14:27:01 GMT+2 Sleep Software Sleep pid=90: Using AC 7 secs 23/07/15 14:27:08 GMT+2 Wake Wake [CDNVA] due to power-button/User: Using AC
Now do the math and calculate the non-sleep uptime. (6540 secs - 108 secs = 6432 secs).
Depending on your operating system and the hibernation mode you set, you may have to alter the grep part in the above command. Check
pmset -g log for the appropriate strings. You also may omit the ' Wake ' part of the command to simplfy the output.