How to display the uptime of a Linux server?

Linux uptime tutorial

How long has my Linux machine been running? This information corresponds to the uptime, and under Linux there's a command of the same name to obtain this information. We're going to learn how to use it and analyse the results it returns.

1. The uptime command

How to order uptime from Linux is one of the simplest and most practical commands in Linux. Running it without parameters yields some interesting information

uptime

The result is a single line showing the current time, the uptime (in days and hours), the number of users currently connected to the system and the average system load.

For example, on my test machine, here is the line obtained:

14:51:57 up 44 min, 1 user, load average: 0.00, 0.00, 0.00
uptime linux

If we take a closer look at the result of the command, here's how to interpret it:

  • 14:51:57 : l’heure actuelle, à savoir 14h51 et 57 secondes
  • Up 44 min : ma machine est démarrée depuis 44 minutes ! On pourrait avoir une valeur sous la forme « Up 10 days » qui indique que la machine tourne depuis 10 jours
  • 1 user : le nombre d’utilisateurs actuellement connecté sur mon système. Là, il n’y a que moi. Cela ne correspond pas au nombre d’utilisateurs total sur la machine, mais bien les utilisateurs connectés.
  • load average: 0.00, 0.00, 0.00 : la charge moyenne de ma machine, ici elle est nulle, car ma machine est inactive. Elle correspond à la charge CPU sur la dernière minute, les 5 dernières minutes et les 15 dernières minutes, ce qui donne la tendance.

The uptime command obtains startup information from /proc files like most other commands. In addition, it uses the /var/run/utmp to obtain information on connected users.

Although Linux's uptime command is handy without options, there are a few that are useful in some cases.

With the "-p" option, you only get the uptime, without any other line information.

uptime -p

This command returns :

Up 44 minutes

The "-s" option is used to obtain the uptime in another form. In fact, rather than obtaining the information that the machine has been running for 44 minutes, the command will give us the date and time at which the machine was started. Indirectly, this saves you the trouble of doing the calculation yourself.

uptime -s

In addition, the "-V" option displays the command version and the "-h" option displays the uptime command help.

The uprecords command

The uptime command only indicates how long your system will run. There's a handy utility called uprecords "This is where you'll find a history of your machine's uptimes. Pretty cool, isn't it? It shows your Linux system's best uptimes, i.e. the times the machine has been on the longest (the race for the best uptime!), with additional information on boot time, duration and Linux kernel version.

Under Debian or Ubuntu, installation is very simple:

sudo apt-get update
sudo apt-get install uptimed

Once uptimed has been installed, you can use the uprecords command to display the various records linked to your machine's uptime.

uprecords

A word of warning: you won't get any recordings in the history immediately, as recording starts as soon as the uptimed package is installed on your machine. In any case, it's only a bonus: the choice is yours.

After reading this article, you will be able to check your Linux server's uptime (Debian, Ubuntu, Rocky Linux, etc.).

Resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *