且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linux下如何查看系统启动时间和运行时间

更新时间:2022-03-06 18:10:15

Linux下如何查看系统启动时间和运行时间

1.uptime命令
输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.00

2.查看/proc/uptime文件计算系统启动时间
cat /proc/uptime
输出: 5113396.94 575949.85
第一数字即是系统已运行的时间5113396.94 秒,运用系统工具date即可算出系统启动时间

代码: 全选 date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"


输出: 2008-11-09 11:50:31

3.查看/proc/uptime文件计算系统运行时间

代码: 全选 cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系统已运行:%d天%d时%d分%d秒\n",run_days,run_hour,run_minute,run_second)}'


输出:系统已运行:59天4时13分9秒

Linux查看系统开机时间

2014-05-29 16:21 by 潇湘隐者, 48349 阅读, 1 评论, 收藏编辑

有时候需要查看Linux系统运行了多久时间,此时需要知道上次开机启动时间; 有时候由于断电或供电故障突然停机,需要查看Linux开机时间/重启时间;  下面总结一些查看Linux开机关机时间的方法(非常全面)

1: who 命令查看

      who -b 查看最后一次系统启动的时间。

      who -r 查看当前系统运行时间

[root@DB-Server ~]# who -b

         system boot May 11 09:27

Linux下如何查看系统启动时间和运行时间

Linux下如何查看系统启动时间和运行时间

2: last  reboot

如下所示last reboot可以看到Linux系统历史启动的时间。 重启一下操作系统后,然后

[root@DB-Server ~]# last reboot

reboot system boot 2.6.9-42.ELsmp Thu May 29 15:25 (00:07)

reboot system boot 2.6.9-42.ELsmp Sun May 11 09:27 (18+05:55)

wtmp begins Mon May 5 16:18:57 2014

Linux下如何查看系统启动时间和运行时间

如果只需要查看最后一次Linux系统启动的时间

[root@DB-Server ~]# last reboot | head -1

reboot system boot 2.6.9-42.ELsmp Thu May 29 15:25 (00:08) 

3:TOP命令查看

    如下截图所示,up后表示系统到目前运行了多久时间。反过来推算系统重启时间

Linux下如何查看系统启动时间和运行时间4:w  命令查看

4: w命令查看

如下截图所示,up后表示系统到目前运行了多久时间。反过来推算系统重启时间

5:uptime 命令查看

Linux下如何查看系统启动时间和运行时间

6: 查看/proc/uptime

[root@DB-Server ~]# cat /proc/uptime

1415.59 1401.42

[root@DB-Server ~]# date -d "`cut -f1 -d. /proc/uptime` seconds ago"

Thu May 29 15:24:57 CST 2014

[root@DB-Server ~]# date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"  
2014-05-29 15:24:57

参考资料:

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

http://www.averainy.info/linux-system-operation-time-and-the-view-of-the-latest-powered-up-time/





About Me

.............................................................................................................................................

● 本文整理自网络

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客园地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群:230161599     微信群:私聊

● 联系我请加QQ好友(646634621),注明添加缘由

● 于 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

.............................................................................................................................................

小麦苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麦苗出版的数据库类丛书http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(xiaomaimiaolhr)及QQ群(DBA宝典),学习最实用的数据库技术。

Linux下如何查看系统启动时间和运行时间Linux下如何查看系统启动时间和运行时间Linux下如何查看系统启动时间和运行时间

   小麦苗的微信公众号          小麦苗的QQ群             小麦苗的微店

.............................................................................................................................................

Linux下如何查看系统启动时间和运行时间
Linux下如何查看系统启动时间和运行时间
Linux下如何查看系统启动时间和运行时间