As a Linux user, or as a server administrator, you need to regularly understand how long your servers have been up and running to understand their patch levels. What that means is that if a major update was recently rolled out, but a server has been up for a few weeks, you know that the system wasn’t upgraded.
We can find the uptime of a Linux system with the use of the uptime command. The command provides an output in the following order.
- the current time
- the total uptime
- the number of active users and
- the average system loads for the past 1, 5 and 15 minutes.
Also read: Sudo Command in Linux/Unix
Using the uptime Command in Linux
The uptime command, being a pretty straightforward one, has very few options that you need to know. Let’s start with the most basic usage of the command.
1. Basic Usage of the uptime command
root@ubuntu:~# uptime 06:48:04 up 22:19, 2 users, load average: 0.16, 0.03, 0.01 root@ubuntu:~#
Options for the uptime command
Let’s figure out what options we have available with the uptime command. As we mentioned, it’s a straightforward command so the options available are going to be very few too.
We’ll make use of the –help or -h option to find the available command options for the uptime command.
root@HowLinux: ~# uptime --help 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).
You can also make use of the man command to learn more about the usage of the “uptime” command.
The pretty (-p) option
The -p option gives the user a pretty output and only displays the uptime in days, hours, minutes, and seconds format. Let’s see how that works.
root@HowLinux: ~# uptime -p up 5 minutes
The since (-s) option
You might want to figure out the exact time when the system was first powered on instead of the time elapsed since it was powered. The “since” option allows you to see exactly that.
root@HowLinux: ~# uptime -s 2019-12-16 16:25:28
As you can see, my system has been up for just a few minutes so it shows the time that I powered it on today.
You may like: Colorize Your Bash Prompt With This Simple Trick
The version (-V) option
If you want to know the version of the uptime package installed in your system, you may use the -V option to find that out. Let’s see the output that we get when we use the uptime command on our system.
root@HowLinux: ~# uptime -V uptime from procps-ng 3.3.12
As you might have noticed, this was one of the simplest and straightforward commands you’ve used in Linux. You run the command (with or without options) and still get the required information, and you’re done.
We’ll be looking into complex, and flexible bash commands in future articles. Until then, keep practicing and you will become efficient with Linux very soon!