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 thier task.

For eg. 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.

Below are the 4 ways to find out uptime of system.

Command 1 : uptime

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

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

Command 2: cat /proc/uptime

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

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

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

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