2

How can I see when my PC was rebooted? I need to know the last 10 times.

  • What OS is your PC using? – fpmurphy Jul 16 '16 at 9:07
  • 2
    @DarkHeart. No need for the pipe to grep. Use last reboot – fpmurphy Jul 16 '16 at 9:14
  • last reboot gave me two results! last reboot reboot system boot 4.5.0-2-amd64 Thu Jul 14 18:16 still running reboot system boot 4.5.0-2-amd64 Sun Jul 3 21:42 still running – Jasen Jul 16 '16 at 9:20
  • @fpmurphy1 Do you want to post that as an answer? Don't want to rip off your solution. ;) – n.st Jul 16 '16 at 9:40
3

Edit: As @fpmurphy1 mentioned in a comment, there's no need for all the runlevel grepping below.
A simple last reboot -n 10 will do.


last -xF | grep -e 'lvl 2' -e 'lvl 5' | head -10

last is mainly used to check when and for how long a certain user was logged in (also see lastlog for that), but the log file it uses (/var/log/wtmp by default) also logs system reboots and runlevel changes.

-x includes these runlevel changes in the output and -F prints the full date and time (instead of an abbreviated form). The normal multi-user mode is usually runlevel 2, so we grep for that and extract the first (i.e. most recent) 10 results.

$ last -xF | grep 'lvl 2' | head -10
runlevel (to lvl 2)   4.6.3-040603-gen Sat Jul 16 08:41:02 2016 - Sat Jul 16 11:08:37 2016  (02:27)    
runlevel (to lvl 2)   4.6.3-040603-gen Fri Jul 15 14:37:20 2016 - Fri Jul 15 20:58:40 2016  (06:21)    
runlevel (to lvl 2)   4.6.3-040603-gen Thu Jul 14 22:50:43 2016 - Thu Jul 14 22:52:07 2016  (00:01)    
runlevel (to lvl 2)   4.6.3-040603-gen Thu Jul 14 13:50:13 2016 - Thu Jul 14 22:50:12 2016  (08:59)    
runlevel (to lvl 2)   4.6.3-040603-gen Tue Jul 12 13:17:37 2016 - Thu Jul 14 00:06:28 2016 (1+10:48)   
runlevel (to lvl 2)   4.6.3-040603-gen Tue Jul 12 10:21:00 2016 - Tue Jul 12 11:07:47 2016  (00:46)    
runlevel (to lvl 2)   4.6.3-040603-gen Mon Jul 11 21:56:36 2016 - Mon Jul 11 23:35:26 2016  (01:38)    
runlevel (to lvl 2)   4.6.3-040603-gen Mon Jul 11 07:37:25 2016 - Mon Jul 11 09:25:13 2016  (01:47)    
runlevel (to lvl 2)   4.6.3-040603-gen Sun Jul 10 16:40:55 2016 - Sun Jul 10 23:14:01 2016  (06:33)    
runlevel (to lvl 2)   4.6.3-040603-gen Fri Jul  8 14:52:26 2016 - Sun Jul 10 13:13:59 2016 (1+22:21)   

  • I get no results at all from that. – Jasen Jul 16 '16 at 9:24
  • all my debian systems seem to use runlevel 5, but wtmp seems to only go back a couple of weeks, – Jasen Jul 16 '16 at 9:30
  • @Jasen If the system has been running continously for a long time, your wtmp might have been logrotated since the reboot. On Debian, wtmp is rotated monthly and the file from the previous month is kept as wtmp.1. You can try looking at that one (last -f /var/log/wtmp.1), but if your system has been online longer than two months, you won't be getting your last 10 boot times this way. – n.st Jul 16 '16 at 9:31
  • @Jasen You're right, runlevel 2 seems to be Ubuntu-specific. I just checked an actual Debian system and it does indeed use runlevel 5. I've updated the search string in my answer. – n.st Jul 16 '16 at 9:35
0

The classic UNIX command for this is uptime which knows how long the current kernel has been running and also gives the current load.

0

You can use # tuptime -l -S-10 and it will report the date and time of the last 10 events of startup/shutdown.

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.