uptime

system informationLinux/Unix
The uptime command is one of the most frequently used commands in Linux/Unix-like operating systems. uptime Tell how long the system has been running

Quick Reference

Command Name:

uptime

Category:

system information

Platform:

Linux/Unix

Basic Usage:

uptime [options] [arguments]

Common Use Cases

    Syntax

    uptime [options]

    Options

    Option Description
    -p, --pretty Show uptime in pretty format (time since boot only)
    -s, --since Show the date and time the system booted up
    -h, --help Display help and exit
    -V, --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the uptime command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Display system uptime and load uptime
    # Show only the uptime (time since last boot) uptime -p
    # Show the time when the system booted uptime -s
    # Advanced Examples Advanced
    # Get uptime in a script and process it
    UPTIME_OUTPUT=$(uptime) echo "System status: $UPTIME_OUTPUT" # Extract load average values using awk uptime | awk '{print $10, $11, $12}' # Check if system has been running for more than a day if uptime | grep -q "day"; then echo "System has been running for at least a day" fi # Format uptime for logging echo "$(date): $(uptime)" >> /var/log/system-status.log # Monitor system load over time while true; do echo "$(date +%H:%M:%S) - $(uptime)" sleep 60 done # Parse uptime for monitoring script UPTIME_SECONDS=$(awk '{print $1}' /proc/uptime) echo "System has been up for $UPTIME_SECONDS seconds" # Check load average and send alert if too high LOAD=$(uptime | awk '{print $(NF-2)}' | sed 's/,//') if (( $(echo "$LOAD > 5.0" | bc -l) )); then echo "High load detected: $LOAD" fi # Create a simple system status dashboard echo "===== System Status =====" echo "Date: $(date)" echo "Uptime: $(uptime -p)" echo "Boot time: $(uptime -s)" echo "Load: $(uptime | awk -F'load average: ' '{print $2}')" echo "======================="

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `uptime` command is a simple yet essential system utility in Unix and Linux systems that provides a snapshot of the system's operational status. This command displays three primary pieces of information: 1. **System Uptime**: How long the system has been running since it was last booted. This is typically shown in days, hours, and minutes. 2. **Current Time**: The current system time when the command was executed. 3. **Load Averages**: A set of three numbers representing the average system load over the past 1, 5, and 15 minutes respectively. These values indicate the average number of processes that were either running or waiting for CPU time during those periods. System administrators and users find the `uptime` command valuable for several reasons: - **System Stability Monitoring**: A high uptime generally indicates a stable system that hasn't crashed or required reboots. Many administrators take pride in maintaining systems with long uptimes, though regular reboots for security updates are also important. - **Performance Troubleshooting**: The load average values are crucial for quickly assessing if a system is under stress. Generally, load averages should be below the number of CPU cores available in the system. Higher values may indicate resource contention or performance issues that need investigation. - **Availability Tracking**: In server environments, uptime is an important metric for calculating system availability percentages and adherence to service level agreements (SLAs). - **Boot Time Reference**: Sometimes it's important to know when a system was last restarted, which can be determined from the uptime information. While the traditional `uptime` command displays all this information in a single line, modern versions offer the `-p` (pretty) option to display only the uptime in a more human-readable format, and the `-s` option to show the exact time when the system was booted. The load average values require some interpretation. On a single-core system, a load average of 1.0 means the CPU is exactly at capacity. On a multi-core system, you need to divide the load by the number of cores to assess utilization percentage. For example, a load average of 4.0 on an 8-core system represents approximately 50% CPU utilization. Increasing load averages (reading from right to left: 15min, 5min, 1min) may indicate a growing problem, while decreasing values suggest the system is recovering from a period of high activity. The `uptime` command is often used in conjunction with other monitoring tools like `top`, `htop`, `vmstat`, and `sar` to provide a more comprehensive view of system performance. It's also commonly included in automated monitoring scripts and system health checks due to its simplicity and the valuable information it provides.

    Related Commands

    These commands are frequently used alongside uptime or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the uptime command works in different scenarios.

    $ uptime
    View All Commands