Linux Uptime Command Examples

The Linux uptime command is often used when troubleshooting a Linux system. One of the first puzzles to solve when investigating an outage may be to check if a system has been rebooted, or how long it has been available for. Quite often its as simple as running the uptime command, but there are a few additional options that it is useful to be aware of.

First of all – do you have the uptime command? The answer is most certainly yes! The uptime command is present on all Linux distributions (such as Ubuntu, Red Hat, Centos etc), and many other operating systems including Unix and VMware ESXi. It can generally be found at /usr/bin/uptime.

Linux Uptime Command – Basic Syntax

Running uptime -h displays the basic syntax for the uptime command:

$ uptime -h

Usage:
 uptime [options]

Options:
 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

First of all, if uptime is ran without any options you should see something like the following output:

$ uptime
 11:32:57 up  2:53,  1 user,  load average: 0.29, 0.09, 0.02

As you can see from the output above, the uptime command returns set of values that show the current time, the amount of time the system has been running, the number of users currently logged in to the system, and the system load average for the past 1, 5 and 15 minutes.

Note: The system load averages show the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access.

Adding the -p option to the uptime command gives a more concise output:

$ uptime -p
up 2 hours, 54 minutes

Use the Uptime Command to Find Out Last Boot Time

The uptime -s command can be used to output the time and date of when the system was last started up. For example:

$ uptime -s
2022-01-25 08:39:03

Check Uptime of Remote Linux Systems

With the help of SSH, we can check the uptime of remote Linux systems easily (providing SSH has been configured to allow access). For example:

$ ssh -q <host> /usr/bin/uptime

Other Tools to Output Uptime on Linux

Whilst running uptime is really all you need to get uptime information, there are other tools on Linux that also output uptime information. For example, the top command includes uptime information at the top of it’s output:

top - 11:34:26 up  2:55,  1 user,  load average: 0.06, 0.06, 0.01
Tasks: 202 total,   1 running, 201 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.0 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

And the w command displays uptime information along with details of logged in users:

$ w
 12:14:13 up  3:35,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
cloud_us pts/0    0.0.0.0     08:44    1.00s  0.08s  0.00s w

As with the uptime command, these tools look at files under /proc for their information, including:

$ cat /proc/uptime
10565.19 20937.31

Check Uptime on Windows Operating Systems

The uptime command isn’t available natively on Windows, though you can retrieve the last boot time by running systeminfo:

systeminfo | findstr "System Boot Time"
 System Boot Time:          17/01/2022, 12:27:44

Summary

In this article you have learned about how to output the last boot time of a Linux system using the Linux uptime command. We also covered how you can see uptime information using other tools such as top and w. Finally, we also mentioned how you can get the uptime of Windows systems using the systeminfo command.

Related posts

Mastering the Linux ifconfig Command

Docker Exec Command With Practical Examples

Debugging with Git Bisect

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More