Skip to content

Uptime

Tell how long the system has been running.


Show the container uptime instead of system uptime

uptime --container

Show uptime in pretty format

uptime --pretty

isplay values in a raw format. Current time and uptime are displayed in seconds

uptime --raw

System up since

uptime --since

Show uptime as it is

uptime | sed -E 's/^[^,]*up *//; s/, *[[:digit:]]* users?.*//; s/min/minutes/; s/([[:digit:]]+):0?([[:digit:]]+)/\1 hours, \2 minutes/' 

Show uptime in days, hours and minutes

uptime | awk -F'( |,|:)+' '{d=h=m=0; if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}'

Print uptime in minutes

uptime_minutes() {
    local up minutes=0
    up=$(uptime -p)

    set -- $up
    shift  # drop "up"

    while [ $# -gt 1 ]; do
        case $2 in
            day*)    minutes=$((minutes + $1 * 1440)) ;;
            hour*)   minutes=$((minutes + $1 * 60)) ;;
            minute*) minutes=$((minutes + $1)) ;;
        esac
        shift 2
    done

    printf "%s minutes\n" "$minutes"
}