Using the uptime Command on Linux

In this tutorial, we will be showing you how to use the uptime command on a Linux device.

uptime Command on Linux

The uptime command allows you to get information about how long your Linux has been running.

Alongside the running time, this tool provides a variety of other bits of information. This data includes the number of active users, the system load average, and the current time.

Using an option, you can use the uptime command to get the exact time your system booted. Additionally, you can also get a prettified uptime format.

This Linux tool is helpful for checking how long your system has been running and seeing exactly when you started it.

As a core part of Linux, you should be able to use this command on almost any Unix or Linux-based operating system.

The Syntax of the uptime Command on Linux

Using the uptime command on Linux is straightforward. It can work without any options, meaning you can simply type in “uptime” into the terminal.

The command will print the current time, uptime, active users, and load average when used without any options.

uptime [OPTIONS]

This command only has four options that you can use. Only two of those options make changes to the uptime commands output. These options are what we have shown below.

  • -p, --pretty – Displays a prettier and more readable version of the uptime.
  • -s, --since – Shows the time when you initially started up the system.
  • -h, --help – Prints out a simple help message, showing all options for the command.
  • -V, --version – Outputs the current version of the uptime command.

Over the next couple of sections, we will show you how each of these options work, and how they modify the output.

Basic Usage of the uptime Command

Let us start by exploring the most basic usage of the uptime command. Simply put, all we need to do is use “uptime” without any options.

Using the uptime command like this will print us the current time, the uptime, the number of active user sessions, and the load average.

uptime

After running the tool, you should see something like what we have shown below displayed in your terminal.

 10:46:48 up 1 day,  6:15,  3 users,  load average: 0.09, 0.07, 0.10

From this, we can see the following information is provided to us

  • The time is currently “10:46” am.
  • Our Linux device has been up for 1 day, 6 hours, and 15 minutes.
  • We currently have 3 active Linux user sessions running on our device.
  • Finally, our systems load average is 0.09 in the last minute, 0.07 in the last 5 minutes, and 0.10 in the last 15 minutes.

The uptime Commands Pretty Option on Linux

The Linux uptime command has options that allow you to change what it outputs. One of these options is called the “pretty” option.

This option tells the tool that it should print the uptime in a pretty, easier-to-read format. When this option is used, only the uptime is displayed. All other information is discarded during output.

You can invoke this option by utilizing “-p” or “--pretty” alongside the command.

uptime -p

Looking at the example result below, you can easily see how long our Linux device has been running.

The uptime is now is written clearly and should be easily readable by the end-user.

up 1 day, 6 hours, 15 minutes

Using the uptime Command to Get the System Start Time

The uptime command on Linux also can tell you exactly when you started the system.

To tell the uptime tool to report the time when you started the system, you will want to use the “-s” or “--since” options.

Using this option will get the exact time and date that the Linux operating system started running.

uptime -s

For example, if we were to run the above command on our Linux system, we would get the following timestamp in our terminal.

From this, we can see our system hit its “running” state on the 1st of April at 4am.

2022-04-01 04:31:15

Working out the Version of uptime on the Linux System

The uptime command also has built-in functionality that allows you to check what version of the tool you are using. While this tool doesn’t typically get a considerable amount of changes, it can be helpful in working out any differences in output.

To get the version of uptime running on your Linux system, you can use the “-V” or “--version” options.

uptime -V

After running the command above, you will likely see something like what we have shown below.

uptime from procps-ng 3.3.17

This simple string tells us our version of uptime is from the “procps-ng” packages and is version 3.3.17.

Getting Help from the uptime Command on Linux

Like most commands on Linux, the uptime command also has a built-in help screen. While not as informative as the man pages are for the command, they are useful for quickly looking at available options.

To get the help pages of the uptime command, all you need to do is utilize the “-h” or “--help” option.

uptime -h

From this, you will get a simple help page like what we have shown below. If you are curious about what any options do, make sure to go back through our guide as we cover all of them.

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

For more details see uptime(1).

Conclusion

This guide has gone over the various ways to use the uptime command on your Linux or Unix-based operating system.

While a straightforward tool, it can be helpful if you want to check how long your system has been running. You can also use it to see exactly when you booted the device up.

If you have any questions about the uptime tool and how to use it, please comment below.

Be sure also to check out our many other Linux command guides or our general Linux tutorials.

Leave a Reply

Your email address will not be published.