45

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

63

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).

  • tells me exactly what i want. id give you an extra +1 if i could for the nice date calculation. – Octopus May 24 '14 at 6:14
0

With the uptime implementation from procps 3.3.6 or newer, this will perfectly do what you want:

$ uptime --since
2018-07-24 09:22:50
0

Just open a terminal and type "top" : read at the top of the screen for the uptime.

0

If procinfo is installed, you can also use:

$ procinfo | grep Bootup
Bootup: Mon Sep 26 09:27:26 2016   Load average: 0.68 1.10 1.67 2/2783 4828

You can install it with sudo apt-get install procinfo

2

Use tuptime, you get all the information that you need, for example:

$ tuptime -e
Startup:  1  at  08:03:58 10/08/15
Uptime:   6 hours, 56 minutes and 7 seconds
Shutdown: OK  at  15:00:05 10/08/15

Downtime: 17 hours, 8 minutes and 14 seconds

Startup:  2  at  08:08:20 11/08/15
Uptime:   6 hours, 51 minutes and 38 seconds
Shutdown: OK  at  14:59:58 11/08/15

Downtime: 17 hours, 7 minutes and 46 seconds

Startup:  3  at  08:07:45 12/08/15
Uptime:   6 hours, 50 minutes and 47 seconds
Shutdown: OK  at  14:58:32 12/08/15

Downtime: 17 hours, 5 minutes and 18 seconds

Startup:  4  at  08:03:51 13/08/15
Uptime:   6 hours, 55 minutes and 12 seconds
Shutdown: OK  at  14:59:03 13/08/15

Downtime: 17 hours, 14 minutes and 20 seconds

Startup:  5  at  08:13:24 14/08/15
Uptime:   1 hours, 28 minutes and 14 seconds

System startups:    5   since   08:03:58 10/08/15
System shutdowns:   4 ok   -   0 bad
Average uptime:     5 hours, 48 minutes and 24 seconds
Average downtime:   13 hours, 43 minutes and 7 seconds
Current uptime:     1 hours, 28 minutes and 14 seconds   since   08:13:24 14/08/15
Uptime rate:        29.74 %
Downtime rate:      70.26 %
System uptime:      1 days, 5 hours, 2 minutes and 1 seconds
System downtime:    2 days, 20 hours, 35 minutes and 39 seconds
System life:        4 days, 1 hours, 37 minutes and 40 seconds
20

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, …).

  • 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 '14 at 16:49
  • 1
    This seems to be in UTC(?) although the output doesn't say so. – Octopus Oct 15 '14 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 '14 at 15:09
  • For date I get "jue abr 12 12:54:51 -03 2018". For uptime I get "12:53:30 up 30 days, 24 min...". For who -b I get "system boot 1969-12-31 21:00" – dstonek Apr 12 '18 at 15:57
  • @dstonek: was your system running in 1969? I thought not...it means you are probably getting an error from something and the -1 is translated to a time just before the Unix 'epoch'. Output will vary with locale; you have demonstrated that. – Jonathan Leffler Apr 12 '18 at 16:05
26

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.
  • 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 '14 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 '14 at 15:19
  • The output is UTC :-( – guettli Aug 24 '16 at 15:04

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.