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.
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)
Command 3: w
[email protected]:~$ 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
Command 4: top