Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a command I can type in a terminal that will tell me the last time a machine was rebooted?

share|improve this question
    

3 Answers 3

up vote 19 down vote accepted

uptime

If you want it in numerical form, it's the first number in /proc/uptime (in seconds), so the time of the last reboot is

date -d "$(</proc/uptime awk '{print $1}') seconds ago"

The uptime includes the time spent in a low-power state (standby, suspension or hibernation).

share|improve this answer
    
tells me exactly what i want. id give you an extra +1 if i could for the nice date calculation. –  Octopus May 24 at 6:14

You can use uptime or last

To see only the last time

last reboot -F | head -1 | awk '{print $5,$6,$7,$8,$9}'

more generically

last reboot

Note and warning

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.
share|improve this answer
    
it should be checked whether this works also for machines that have been running for more than one year, because I fear that the date format depends on how far away the date is (since the year is missing) –  Walter Tross May 24 at 15:06
    
@WalterTross Thanks for notice. It's possible to patch adding -F option so it will print the year too. –  Hastur May 24 at 15:19

I usually use who -b, which produces output such as:

$ who -b
         system boot  2014-05-06 22:47
$

It tells me the date and time when the machine was last booted, rather than the time that has elapsed since it was last booted.

This command works on many other Unix systems too (Solaris, …).

share|improve this answer
    
It possible to use who -r (runlevel) too that produces an output like run-level 2 2014-05-06 22:47 with a number of words that should not depend from locale language settings (e.g. "system boot" 2 words, should be "Avvio di sistema" in Italian, 3 words) –  Hastur May 24 at 16:49
    
This seems to be in UTC(?) although the output doesn't say so. –  Octopus Oct 15 at 15:04
    
@Octopus: On my Mac, I get different results from TZ=US/Pacific who -b and TZ=UTC0 who -b (Mac OS X 10.9.5 tested); likewise on Linux (Ubuntu 14.04 tested). That means it produces local time, where 'local time' is determined by the TZ environment variable. (If TZ is unset, it probably behaves as if it were TZ=UTC0 unless overridden by a setting in /etc/defaults or something similar.) –  Jonathan Leffler Oct 15 at 15:09

Your Answer

 
discard

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.