Answers:
如果您希望使用数字形式,则它是第一个数字/proc/uptime
(以秒为单位),因此上次重新启动的时间为
date -d "$(</proc/uptime awk '{print $1}') seconds ago"
正常运行时间包括在低功耗状态(待机,暂停或休眠)中花费的时间。
您可以使用uptime
或last
只看最后一次
last reboot -F | head -1 | awk '{print $5,$6,$7,$8,$9}'
更一般地
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.
-F
选项,以便它也可以打印年份。
我通常使用who -b
,产生如下输出:
$ who -b
system boot 2014-05-06 22:47
$
它告诉我上次启动计算机的日期和时间,而不是自上次启动以来经过的时间。
此命令也可以在许多其他Unix系统上使用(Solaris,…)。
who -r
(运行级别)产生类似run-level 2 2014-05-06 22:47
不依赖于语言环境设置的多个单词的输出(例如,“系统启动”为2个单词,意大利语为“ Avvio di sistema”,为3个单词)
TZ=US/Pacific who -b
和获得了不同的结果TZ=UTC0 who -b
(已测试Mac OS X 10.9.5);同样在Linux上(经过Ubuntu 14.04测试)。这意味着它将产生本地时间,其中“本地时间”由TZ环境变量确定。(如果未设置TZ,TZ=UTC0
除非被某个设置/etc/defaults
或类似设置所覆盖,否则它的行为可能就好像是TZ 。)
date
我得到了“ jue abr 12 12:54:51 -03 2018”。因为uptime
我得到“ 12:53:30 30天24分钟...”。因为who -b
我得到“系统启动1969-12-31 21:00”
-1
其转换为Unix“时代”之前的时间。输出将随区域设置而变化;你已经证明了这一点。
使用tuptime,您可以获得所需的所有信息,例如:
$ 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