How long has my Linux system been running?

126,258

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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
Share:
126,258

Related videos on Youtube

Octopus
Author by

Octopus

Updated on September 18, 2022

Comments

  • Octopus
    Octopus almost 2 years

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

  • Walter Tross
    Walter Tross about 10 years
    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)
  • Hastur
    Hastur about 10 years
    @WalterTross Thanks for notice. It's possible to patch adding -F option so it will print the year too.
  • Hastur
    Hastur about 10 years
    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)
  • Octopus
    Octopus over 9 years
    This seems to be in UTC(?) although the output doesn't say so.
  • Overmind Jiang
    Overmind Jiang over 9 years
    @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.)
  • guettli
    guettli almost 8 years
    The output is UTC :-(
  • dstonek
    dstonek about 6 years
    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"
  • Overmind Jiang
    Overmind Jiang about 6 years
    @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.
  • Systems Rebooter
    Systems Rebooter over 3 years
    Exactly what I was looking for! Thanks!
  • Abdull
    Abdull over 2 years
    I have to run sudo last boot (last root with root rights) to get full output.
  • Hastur
    Hastur over 2 years
    @Abdull Hi, even in my actual system (Ubuntu LTS -- util-linux 2.34) the last reboot command does not require root priviledges and gives the same answer with or without sudo. (The same if I add the -F option). Note, however, that is last reboot not last boot. It is interesting/useful to know on which system/version you find it was needed (it may even depend on the specific local configuration -- namely on which log file you are pointing/ have access too).
  • Hastur
    Hastur over 2 years
    @guettli Sorry to see it so later, I think you may find useful --time-format iso or a custom set of TIME FORMATS to suit your needs.