Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> 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

能看到歷史上的每一次啟動記錄:

[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

只看最近一次:

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

Linux 查看系統開機與關機時間的六種方法

3. top 命令

最上面那行 up 後面就是已運行的時長,反推即可得開機時間。

Linux 查看系統開機與關機時間的六種方法

4. w 命令

同樣在 up 欄位顯示運行時長。

Linux 查看系統開機與關機時間的六種方法

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

Linux 查看系統開機與關機時間的六種方法

作者:瀟湘隱者 出處:https://www.cnblogs.com/kerrycode/

本欄目更多精彩內容:https://www.bianceng.cn/OS/Linux/

Copyright © Linux教程網 All Rights Reserved