8

This is the command I am using:

last -x|grep shutdown | head -1

but it's giving me the duration with +2 hours:

shutdown system down  3.14-1-amd64     Mon Jul 21 08:43 - 22:19  (13:36)

the last shutdown time (08:43) is correct, but the startup time (22:19, should be 20:19) is incorrect.

Is there a better command to check how long ago the PC was shutdown? or is my DST settings or something else causing this?

PS: I am using Debian testing (Linux rig 3.14-1-amd64 #1 SMP Debian 3.14.12-1 (2014-07-11) x86_64 GNU/Linux)

  • Which O.S. are you using? – tachomi Jul 21 '14 at 19:29
  • 1
    Are you sure that the time is given +2 hours, I have tried it and it worked. – Networker Jul 21 '14 at 19:30
  • In the reboot line that is adjacent to this shutdown line, does it also show the incorrect startup time? – Mark Plotnick Jul 21 '14 at 20:21
  • 2
    who -b gives last system boot time last reboot gives also what command says. If you suspect on DST settings check current date and compare it with real values and let us know – klerk Jul 21 '14 at 20:23
  • 1
    @klerk who -b gives incorrect value: semko@rig:~$ who -b system boot 2014-07-22 00:24 semko@rig:~$ date Mon Jul 21 22:41:35 CEST 2014 . so you can see that it is off by 2 hrs from date. semko@rig:~$ last reboot reboot system boot 3.14-1-amd64 Tue Jul 22 00:24 - 22:41 (-1:-42) is the last entry, and the -1:-42 is just absurd. – şaloma Jul 21 '14 at 20:42
8

According to your output:

shutdown system down  3.14-1-amd64     Mon Jul 21 08:43 - 22:19  (13:36)

You shutdown your system on July 21 at 08:43 and then after 13 hours and 36 minutes on July 21 at 22:19 you boot it up again. You can see how much time your system is up with uptime command. If you want to see the last time you boot up (not shutdown) use the following command:

 last -x | grep reboot

For example my output is:

reboot   system boot  4.4.0-31-generic Mon Aug  1 12:59   still running
reboot   system boot  4.4.0-31-generic Mon Aug  1 01:28 - 08:54  (07:25)

Now it's easy to understand that I booted up my system on August 1 at 12:59 and it's still running. And I was working with my computer for 7 hours and 25 minutes from 01:28 to 08:54 on August 1. Hope it will be useful! :-)

3

I'm using OS Fedora and command:

last -1x shutdown
shutdown system down  3.15.3-200.fc20. Fri Jul 11 12:31 - 12:31  (00:00)
wtmp begins Sat Dec 28 12:28:14 2013

1

An other good alternative is the use of the command tupime.

The following example list since the last two startups, with the "Shutdown" and "Downtime" registers that your are interested:

$ tuptime  -l -S-2
Startup:  1379  at  13:51:57 06/01/18
Uptime:   10 minutes and 54 seconds
Shutdown: OK  at  14:02:51 06/01/18
Downtime: 19 hours, 31 minutes and 53 seconds

Startup:  1380  at  09:34:44 07/01/18
Uptime:   22 minutes and 59 seconds
1

If you are using systemd (and have journald logs permanently stored on disk), you could use journalctl -b-1 and then go to the end of the logs

0

You could call uptime and do the math:

# uptime
 11:56:42 up 64 days, 13:27,  4 users,  load average: 0,00, 0,03, 0,11
  • This doesn't help to known about a shutdown or restart, because you are already up at command time. This kind of question is more about "to know when the computer has went off", which is my case too. All we know about logs, but there are always a nicer way to do things, like last. – erm3nda Mar 31 '18 at 20:45
0

As friends said who,last and uptime will help you but you can check /var/log/messages. If your system was idle you would find Mark in logs and find last Mark will help you to find when system down and when system start up syslog write the kernel and services log on /var/log/messages. You can find out when services getting start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.