欢迎来到starnight_cyber的博客

【抄】Linux查看系统启动时间

  本篇简单介绍查看linux系统启动时间的方法介绍。

Last命令

$ last reboot
wtmp begins Mon Nov  2 06:35:26 2020

who命令

$ who -b
         system boot  2020-09-22 03:06

  可以发现,跟上面last命令的输出结果不一致,感觉应该以who -b为准。

TOP命令

  根据系统到目前运行了多久时间,反过来推算系统重启时间。

$ top
top - 12:19:28 up 55 days,  9:13,  2 users,  load average: 0.02, 0.03, 0.00
...

w命令

  根据系统到目前运行了多久时间,反过来推算系统重启时间。

$ w
 12:27:58 up 55 days,  9:21,  2 users,  load average: 0.00, 0.01, 0.00

uptime 命令

  根据系统到目前运行了多久时间,反过来推算系统重启时间。

$ uptime
 12:28:56 up 55 days,  9:22,  2 users,  load average: 0.00, 0.00, 0.00

查看/proc/uptime

$ date -d "`cut -f1 -d. /proc/uptime` seconds ago"
Tue Sep 22 03:06:10 UTC 2020

$ date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S" 
2020-09-22 03:06:10
$ uptime | \
> perl -ne '/.*up +(?:(\d+) days?,? +)?(\d+):(\d+),.*/; $total=((($1*24+$2)*60+$3)*60);
> $now=time(); $now-=$total; $now=localtime($now); print $now,"\n";'
Tue Sep 22 03:06:25 2020

 

参考:

  https://www.cnblogs.com/kerrycode/p/3759395.html

  https://www.thegeekstuff.com/2011/10/linux-reboot-date-and-time

posted @ 2020-11-16 20:31  starnight_cyber  阅读(464)  评论(0编辑  收藏  举报