×

Linux

查看centos的运行时间和启动时间

老斑鸠 老斑鸠 发表于2021-01-15 浏览2863 评论0

1、uptime命令:

运行此 命令将显示系统已经运行了多长时间,它依次显示下列信息:当前时间、系统已经运行了多长时间、目前有多少登陆用户、系统在过去的1分钟、5分钟和15分钟内的平均负载。

[root@cZEqhNpstj ~]# uptime
 21:42:20 up 1 day,  1:50,  1 user,  load average: 1.49, 1.23, 1.28

2、查看/proc/uptime文件计算系统启动时间:cat /proc/uptime

运行此命令会显示以空格分开的2组数值(以秒计),第一个为系统运行时间(即建立新系统运行到现在的时间),第二个为距离上次启动的时间。

[root@cZEqhNpstj ~]# cat /proc/uptime
93177.73 157961.20

3、将/proc/uptime中的时间直观显示:

显示系统运行时间:

[root@cZEqhNpstj ~]# cat /proc/uptime| awk -F ' ' '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("System Running Time: %d Days %d Hours %d Minutes %d Seconds\n",run_days,run_hour,run_minute,run_second)}'
System Running Time: 1 Days 1 Hours 53 Minutes 39 Seconds

显示距离上次重启时间:

[root@cZEqhNpstj ~]# cat /proc/uptime| awk -F ' ' '{run_days=$2 / 86400;run_hour=($2 % 86400)/3600;run_minute=($2 % 3600)/60;run_second=$2 % 60;printf("Distance from the last start time: %d Days %d Hours %d Minutes %d Seconds\n",run_days,run_hour,run_minute,run_second)}'
Distance from the last start time: 1 Days 19 Hours 54 Minutes 17 Seconds

Linux centos