Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was doing a 24 hour code-a-thon and had to reboot numerous times and was wondering if there was a way to tell exactly how many the computer was rebooted or crashed.

share|improve this question
Somewhat related: Is there a tool for tracking uptimes across reboots? – slm May 25 '14 at 12:31

System reboots are usually logged in the binary file /var/log/wtmp. The easiest way to read that file is using the last command which prints lines like this for every reboot:

reboot   system boot  3.10-3-amd64     Fri May  2 19:30 - 21:02 (5+01:32)   

so if you issue last reboot, you'll get a list of all reboots logged to your wtmp file.

share|improve this answer
No need to grep, just last reboot displays the entries by the "user" reboot. – user80551 May 25 '14 at 17:39
That's true, I looked over that little detail when reading last's manpage today (I was expecting it to be a parameter value, not a simple argument...) – mreithub May 25 '14 at 20:27

You can invoke directly

 last reboot

The pseudo user reboot logs in each time the system is rebooted. Thus last reboot will show a log of all reboots since the log file was created.

it gives in addition the time from which starts the logfile (/var/log/wtmp). If you are interested in the past too, there are usually stored one or more files with past logs (/var/log/wtmp.1)...

Here below a little example script to count the number of reboots and crashes in one day.
You can run it with /bin/bash Myscript.sh to have the results for today or /bin/bash Myscript.sh "Tue May 20" to have results for the 20 of May



N_Crash=`last -F  |grep crash  |  grep "$StrDay"  | sort -k 7 -u | wc -l`
N_Reboot=`last -F | grep reboot | grep "$StrDay"  | wc -l `

echo "# Today $Today  Report for crash and reboot on $StrDay  "
echo "# Crashes $N_Crash"
echo "# Reboot $N_Reboot"

Notes: with reboot you have few problem because there is one line each time you reboot.
This crash count is only indicative: you can have many lines (e.g. one for each shell) in case of crash. Even more, if the crash is not abrupt you can have different times for the same crash (maybe a second or a minute if it is in boundary). Moreover, even if this is more rare, you can make crash a shell without a crash of the system. The sort option try to kill duplicate lines for the same time. To have a correct result you should count as reboot only the lines of reboot without crashes between and as crashes the reboot with a crash before.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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