Linux uptime Command Explained [With Examples]

Written by: Linuxopsys   |   Last updated: September 5, 2023

The uptime command in Linux provides information about the system's uptime, showing the amount of time the system has been up and running since its last reboot. It also provides information on the number of users currently logged in and the system load averages for the last 1, 5, and 15 minutes.

Syntax:

uptime [-options]

Where [OPTION] can be one or more of the following:

  • -p, --pretty: Display the uptime in a more human-friendly format.
  • -h, --help: Display help information.
  • -s, --since: Show the date and time since the system was last started.
  • -V, --version: Display version information.

Basic Usage

In general, if you run uptime without any options, it will display the default information.

Simply type:

uptime
running uptime command and its output

This command shows the current time, the system's uptime duration, the number of logged-in users, and the system load averages for the last 1, 5, and 15 minutes.

Understanding the Output

An example of the uptime output looks like:

20:08:23 up 100 days,  2:36,  1 user,  load average: 0.00, 0.01, 0.05
  • Current time: 20:08:23
  • Uptime: The system has been running for 100 days and 2 hours 36 minutes.
  • Logged-in users: There's 1 user currently logged in.
  • Load averages:
    • Last 1 minute: 0.00
    • Last 5 minutes: 0.01
    • Last 15 minutes: 0.05

Reading Load Averages

Load averages represent the average system load over a specified period of time. To be more specific It represents the average number of processes that are either in a runnable state (waiting for CPU time) or in an uninterruptible state (waiting for I/O or other resources).

They are typically presented in three values, reflecting the past 1, 5, and 15 minutes.

For example, if the uptime command returns:

load average: 0.40, 0.30, 0.25
  • 0.40 is the average load for the last 1 minute.
  • 0.30 is the average load for the last 5 minutes.
  • 0.25 is the average load for the last 15 minutes.

General Guidelines for Interpretation:

  • 0.00 - 0.70: System is mostly idle.
  • 0.70 - 1.00: System is using its capacity but is still responsive.
  • 1.00 and above: System might be overloaded. For multi-core systems, multiply the number of cores to assess overload. For instance, on a 4-core system, values above 4.0 might indicate an overload.

More readable format

The -p or --pretty option with the uptime command provides the uptime in a more readable or "pretty" format.

Example:

Without -p:

$ uptime 
02:53:27 up 46 days, 22:23,  1 user,  load average: 0.00, 0.01, 0.05

With -p:

$ uptime -p
up 6 weeks, 4 days, 22 hours, 24 minutes

As you can see, the -p option trims down the output to just show the duration the system has been running, omitting the current time, number of users, and load averages.

If you are curious to know uptime in seconds read /proc/uptime file. The first number in this file represents the total number of seconds the system has been up. To fetch the uptime in seconds use cat /proc/uptime | awk '{print $1}'. For hh:mm:ss awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime.

Date and Time since last reboot

To see the date and time since the last reboot using the uptime command, you would use the -s or --since option.

Example:

$ uptime -s
2023-07-20 04:29:57

In the above example, the system was last started (or rebooted) on July 20th, 2023, at 04:29:57.

Extract uptime Output

For scripting purposes you might need need extract specific information from uptime output, for that you filter out using tools such as awk, sed, etc.

get uptime only

uptime | sed 's/^.* up \+\(.\+\), \+[0-9] user.*$/\1/'
438 days,  1:15

The command is designed to extract the uptime duration from the uptime command's output. This works for system up for more than a day and up less than a day.

Get load average only

uptime | awk -F': ' '{print $2}'
0.01, 0.02, 0.00

This command you've used is extracting the load averages of the system.

There are alternative tools and commands that also provide system uptime along with additional details such as top, htop, w command, procinfo.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment