linux查看系统启动时间

1.uptime命令

root@localhost:/var/log# uptime
06:44:12 up 7 days, 21:44, 1 user, load average: 0.01, 0.03, 0.00

2.查看/proc/uptime文件

root@localhost:/var/log# cat /proc/uptime
683113.07 682104.86

2-1.计算系统启动时间(date命令)

root@localhost:/var/log# date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
2016-10-25 09:00:01

2-2.计算系统运行时间

root@localhost:/var/log# 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)}'
系统已运行:7天21时51分31秒

3.who 命令查看

root@localhost:/var/log# who -b
         系统引导 2016-10-25 08:59
root@localhost:/var/log# who -r
         运行级别 5 2016-10-25 08:59

4.last reboot命令

root@localhost:/var/log# last reboot
reboot   system boot  2.6.32-042stab11 Tue Oct 25 08:59 - 06:54 (7+21:55)   
reboot   system boot  2.6.32-042stab11 Mon Oct 24 15:04 - 08:59  (17:55)    
reboot   system boot  2.6.32-042stab11 Mon Oct 24 15:00 - 15:04  (00:03)    
reboot   system boot  2.6.32-042stab11 Mon Oct 24 08:10 - 15:00  (06:50)    
reboot   system boot  2.6.32-042stab11 Mon Oct 24 07:58 - 08:10  (00:12)    
reboot   system boot  2.6.32-042stab11 Mon Oct 24 07:28 - 07:58  (00:29)    
reboot   system boot  2.6.32-042stab11 Sat Oct 22 07:56 - 07:27 (1+23:31)   
reboot   system boot  2.6.32-042stab11 Sat Oct 22 07:37 - 07:56  (00:18)
root@localhost:/var/log# last reboot | head -1
reboot   system boot  2.6.32-042stab11 Tue Oct 25 08:59 - 06:56 (7+21:56)

5.top命令

top - 06:57:17 up 7 days, 21:57,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  24 total,   1 running,  23 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1048576 total,   954152 free,    38432 used,    55992 buff/cache
KiB Swap:   131072 total,   121632 free,     9440 used.   928059 avail Mem

PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
365 root      20   0   39020  16152   1488 S  0.7  1.5  73:09.13 server_linux_am
  1 root      20   0   42292   3484   1384 S  0.0  0.3   0:24.71 systemd
  2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd/386442
  3 root      20   0       0      0      0 S  0.0  0.0   0:00.22 khelper/386442
 69 root      20   0   41432    460    456 S  0.0  0.0   0:00.00 systemd-udevd
 70 root      20   0   92600   7100   6984 S  0.0  0.7   0:07.27 systemd-journal
102 dbus      20   0   26416    864    680 S  0.0  0.1   0:09.80 dbus-daemon
107 root      20   0   26352   1000    848 S  0.0  0.1   0:07.24 systemd-logind
......

6.w命令

root@localhost:/var/log# w
07:00:33 up 7 days, 22:00,  1 user,  load average: 0.07, 0.03, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
frost    pts/0    124.65.123.238   06:28    0.00s  0.09s  0.01s sshd: 123 [priv]

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注