1.uptime command
output: 16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.00
2. View the /proc/uptime file to calculate the system startup time
cat /proc/uptime
output: 5113396.94 The
first number of 575949.85 is the time the system has been running for 5,13,396.94 seconds, and the system startup time can be calculated using the system tool date
-
Code:
select all
-
date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
Output: 2008-11-09 11:50:31
3. View the /proc/uptime file to calculate the system running time
-
Code:
select all
-
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秒",run_days,run_hour,run_minute,run_second)}'
Output: The system has been running: 59 days, 4:13:9 seconds