Linux-uptime-command

In this tutorial,we will learn about 4 different commands to find system uptime in Linux. Uptime of system means how long the server has been running and up since its last shutdown or reboot.The information about uptime is very useful in many cases it helps to audit how long the server is running and even some system admin use the uptime commands in scripts for their task.

For example Jim booted the Linux system long days ago and now he would like to know since how many days the system is up and running . As per his assumption he booted the server around 6 months ago but he astonished to find out that server uptime was showing only one month.So it means in this period the server was rebooted. The reboot can be of many reasons either hardware failure, power trip,any script or mistake by any super user etc.Now Jim has to find out the reason but one thing is clear system was rebooted.

Find the uptime of Linux system

Given below 4 commands will help you to find the uptime of your Linux Operating System. It works in almost all Linux and Unix based Operating System.

Open the terminal in your Linux box and just write those commands. In each section, we have shown the execution examples and its output.

Command 1 : uptime

The command name itself a self explanatory. It also shows other information like number of users login and load average.

linux@mypc:~$ uptime
 20:43:50 up 8 min, 2 users, load average: 0.94, 0.82, 0.48
 linux@mypc:~$

In below output it shows system is up 8 minutes ago.

Command 2: cat /proc/uptime

To get uptime information we will directly read the proc file called uptime . In given below output, the first number is how long the system has been up(in seconds).
The second number is how much of that time the machine has spent idle(in seconds).

linux@mypc:~$ cat /proc/uptime
 1229.64 4117.92
 linux@mypc:~$

Command 3: w

The w command is smallest command in the Linux system as it has only one alphabetical letter that is ‘w’. With the uptime information , it also shows other useful information.

linux@mypc:~$ w
  20:59:09 up 23 min, 2 users, load average: 0.46, 0.60, 0.58
 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
 linux tty7 :0 20:40 23:03 42.68s 0.27s gnome-sessi
 linux pts/0 :0 20:43 0.00s 0.07s 0.00s w
 linux@mypc:~$

Command 4: top

Top command is used generally by most of the Linux user to check which process is currently running. But the output of top commands has lots of other information. As we are talking about uptime then this top command also has this information in its output. It is at the first line of the screenshot before ‘users’ information.

top
uptime

Read Some More Articles

4 Comments

    1. Hi Ahmed,

      In cat /proc/uptime it will show output having two values. These values are in seconds hence we have to convert the seconds to readable date.
      https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-uptime.html

      Given below is work done in my system.

      sharad@linuxworld:~$ x=$(cat /proc/uptime|awk '{print $1}')
      sharad@linuxworld:~$ echo $x
      267300.30
      sharad@linuxworld:~$ date --date="$x seconds ago"
      Mon Jan 22 20:55:25 IST 2018
      sharad@linuxworld:~$ 
      sharad@linuxworld:~$ date
      Thu Jan 25 23:10:30 IST 2018
      sharad@linuxworld:~$ 
      
      sharad@linuxworld:~$ uptime
       23:10:37 up 3 days,  2:15,  1 user,  load average: 1.18, 1.34, 1.42
      sharad@linuxworld:~$ 
      

      Regards
      Sharad

  1. Worth noting (from Red Hat site):
    The first value represents the total number of seconds the system has been up. The second value is the sum of how much time each core has spent idle, in seconds. Consequently, the second value may be greater than the overall system uptime on systems with multiple cores.

    That would explain why after some 16 minutes after reboot (most of them idle), the 2nd /proc/uptime value reported is roughly 4X the actual uptime in a 4 core machine:

    [root@pmatlab /var/log]$ cat /proc/uptime
    956.52 3734.35

    1. This is what I called wonderful comment and you hit the bulls eye, David !
      While writing this post, I just tried to brief on 4 commands to reach maximum readers.

      I really like to share the Red Hat official link that is https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-uptime.html

      @ Readers, if you are wondering what the hell we are talking about, I will direct you to Command 2 : cat /proc/uptime

      Thanks David!

      Regards
      Sharad

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.