How to find the uptime since last wake from standby

In /var/log/pm-suspend.log, look for the last line looking like this one:

Sun Dec 16 09:30:31 CET 2012: Awake.

That's your last wakeup time. You can calculate your uptime since then the way Paul suggested.

Periodically your logrotate will "rotate" logs to prevent them from growing too big, so you may find an empty pm-suspend.log file. In this case, just look for the pm-suspend.log.1 file (you may find also other log files named like pm-suspend.log.2.gz and so on; you can examine them using zcat or zless).


The pm-suspend program is not the only option how to suspend the computer. My log of this program is now empty, but I have found more reliable command:

cat /var/log/syslog | grep 'systemd-sleep' | grep "Suspending\|resumed"

And the output is:

Oct  2 09:11:48 dmatej-lenovo systemd-sleep[931]: Suspending system...
Oct  2 09:53:10 dmatej-lenovo systemd-sleep[931]: System resumed.
Oct  2 15:02:48 dmatej-lenovo systemd-sleep[27516]: Suspending system...
Oct  2 16:07:19 dmatej-lenovo systemd-sleep[27516]: System resumed.
Oct  2 16:32:48 dmatej-lenovo systemd-sleep[29622]: Suspending system...
Oct  2 17:16:41 dmatej-lenovo systemd-sleep[29622]: System resumed.
Oct  3 00:24:58 dmatej-lenovo systemd-sleep[21316]: Suspending system...
Oct  3 08:17:22 dmatej-lenovo systemd-sleep[21316]: System resumed.
Oct  3 09:09:25 dmatej-lenovo systemd-sleep[24739]: Suspending system...
Oct  3 09:50:47 dmatej-lenovo systemd-sleep[24739]: System resumed.

For desktops/servers running systemd, while there is no direct command that will tell the info directly (as far as I am aware), all the data is captured in the journal.

You can grep the journal, for example:

echo ">> [SUSPEND] Times during current boot"
journalctl -b 0 |grep "]: Suspending system..."
echo ">> [WAKE] Times during current boot"
journalctl -b 0 |grep "PM: Finishing wakeup"

Or, for fancy output, I wrote a python3 script (runs fine on Fedora 23) Sample output:

Initial Boot Timestamp:  2016-01-15 09:31:32 

     Wake Timestamp     |    Suspend Timestamp   |       Awake Time       |
  --------------------  |  --------------------  |  --------------------  |
   2016-01-15 09:31:32  |   2016-01-15 09:36:03  |          0h  4m        |
   2016-01-15 09:36:22  |   2016-01-15 19:15:04  |          9h 38m        |
   2016-01-15 19:22:21  |   2016-01-15 20:00:05  |          0h 37m        |
   ...
   -------------------  |  --------------------  |  --------------------  | 

Summary: Days Since Boot [8.23] | Days Awake [4.14] | Suspend/Wake Cycles: [28]

The script is in github. link to github repo


None of these answers worked for me. But I usefully found sleep.target which is made for exactly this:

$ journalctl -n4 -u sleep.target
nov. 17 17:16:37 kaa systemd[1]: Reached target Sleep.
nov. 17 18:46:22 kaa systemd[1]: Stopped target Sleep.
nov. 17 19:27:31 kaa systemd[1]: Reached target Sleep.
nov. 17 19:45:21 kaa systemd[1]: Stopped target Sleep.

I did not have pm-suspend.log on my machine.

This worked for me:

/usr/bin/pmset -g log | grep Wake | grep "due to" | tail -n1

Also says what woke the computer up. :-)