Updated April 14, 2023
Introduction to Linux uptime
Uptime is defined as a command that returns how long a system has been running and statistics like current time, the number of active sessions of users, and load averages of the system. Not only this but the load time is also tracked at 1, 5- and 15-minutes cadence and uptime command help in collating all these and present as one! This command is one of the most extensively used commands by system admins. The results of uptime command are derived from various locations in a Linux system and then aggregated in a human-readable format and have a lot of options available for its various utility.
In Linux, there are very restricted options available for uptime, and in this section, we will discuss all of those in detail, with having eased off time by looking at the syntax, and later in the article, take a dig at the working of uptime command in Linux.
1. Display all information about uptime without formatting
2. Display the statistics of uptime in a pretty format
3. Displaying the help documentation of uptime
4. Displaying up since time
5. Listing the information of output version
How does the Uptime command work in Linux?
The description of uptime, when present in the console, depicts a one-line display of the following information. At first, it is the current time which depicts when the current command was run. This is to understand and maybe back-calculate from what comes next, uptime, to understand when the system was first to run. Now that we have mentioned the start of the system back-calculated from uptime, this uptime denotes how long the system has been running. The next bit of information is how many users are currently logged in. finally, at a cadence of 1, 5, and 15 minutes, the system’s load average is mentioned.
Now, with all the above descriptions, we need to know 2 main things before we jump on to any of the later descriptions on the working of Linux. The first being what do we mean by system load averages, and the next is where does uptime get all these statistics from? To answer the first one, system load averages are the number of processes that are runnable or uninterruptable state; the runnable state is the process state is the one where either the process is using the CPU or waiting to use the CPU, whereas the uninterruptable state is the process state where the process is waiting for some I/O access like the disk. To answer the next question, the command uptime gathers information from 2 different sets of locations, /var/run/utmp which lists down the users who are currently logged on in the system and the other location being /proc/uptime, which lists out the process information.
On similar lines, the locations mentioned in the above paragraph are in a machine-readable condition, and that is why command-like uptime is required for easy interpretation and conversion to a human-readable format. If you need to cross-check if the uptime provides accurate output to the console, one can utilize the awk or sed command at the /proc/uptime location and get the desired results. The uptime result is also easily accessible through the w command, and the information is present in the top line of the command’s output.
It is now time for us to decode the display of information from the uptime command. When one uses the uptime command, it gets the following line as an output:
09:27:19 up 91 days, 27 min, 9 users, load average: 0.28, 0.27, 0.27
Here, the first highlight mentions the time when the uptime command is run. The next highlight mentions the days and minutes the system has been up to or running. The following highlight is about the number of users logged in, which in this case is 9. And finally, comma-separated CPU load in percentage for past 1, 5, and 15 minutes. The way it works is all the information resides at different locations, and the command uptime tried to reconcile them and present it in a human-readable format. In case one needs to know about an alternate to uptime, he or she can refer to the top command in Linux as a utility. Another similar concept to uptime is tuptime utility which lists out the historical uptime of Linux server along with statistics of the same!
Here are the following examples mention below
Display all information of uptime without formatting
In this option, we see that at 1 minute, the CPU was loaded at 3% (denoted as a fraction), at 5 minutes, the CPU was loaded at 9,% and for the 15th-minute interval, the CPU was loaded at 8% with the system running for 1 min.
Display the statistics of uptime in a pretty format
Displaying the help documentation of uptime
Displaying up since time
Listing the information of output version
With the set of examples and explanation of the way of working for uptime, it is now more eased up on the utility uptime command brings in. it is now left on the readers to start experimenting with uptime and not only stop here, but use the extensive utility of sed and awk command to bring in the same capability of uptime command. Doing this will not only be more satisfying but, in turn, help you check if the uptime command is actually giving the right results or not!
We hope that this EDUCBA information on “Linux uptime” was beneficial to you. You can view EDUCBA’s recommended articles for more information.