{"id":2089,"date":"2012-02-26T23:12:06","date_gmt":"2012-02-26T15:12:06","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=2089"},"modified":"2023-04-28T09:49:42","modified_gmt":"2023-04-28T09:49:42","slug":"how-to-check-server-uptime-in-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-check-server-uptime-in-linux\/","title":{"rendered":"How to Check Server Uptime in Linux"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone wp-image-6823 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/02\/How-to-Check-Server-Uptime-in-Linux.jpg\" alt=\"Server Uptime\" width=\"800\" height=\"500\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/02\/How-to-Check-Server-Uptime-in-Linux.jpg 800w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/02\/How-to-Check-Server-Uptime-in-Linux-300x188.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/02\/How-to-Check-Server-Uptime-in-Linux-768x480.jpg 768w\" data-sizes=\"(max-width: 800px) 100vw, 800px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 800px; --smush-placeholder-aspect-ratio: 800\/500;\" \/><\/p>\n<p>Server uptime is an important metric that indicates how long a system has been running without interruption. In Linux, there are several commands that you can use to check server uptime, including uptime, w, and top.<\/p>\n<p>In this guide, we&#8217;ll cover these commands, along with a few other methods to determine the server uptime.<\/p>\n<h2>Method 1: The uptime Command<\/h2>\n<p>The uptime command is the most straightforward way to check server uptime in Linux. It displays the current time, system uptime, the number of users, and the load average. To use the uptime command, simply run:<\/p>\n<pre>\r\nuptime\r\n<\/pre>\n<p>The output will show the uptime in days, hours, and minutes, along with other system information.<\/p>\n<pre> 22:54:34 up  1:26,  1 user,  load average: 0.11, 0.03, 0.01<\/pre>\n<p>That is:<\/p>\n<ul>\n<li>The current time (22:54:34)<\/li>\n<li>How long the system has been up and running (1 hour 26 Minutes)<\/li>\n<li>How many users are currently logged in (1 user)<\/li>\n<li>The system load averages for the past 1, 5, and 15 minutes (0.11, 0.03, 0.01)<\/li>\n<\/ul>\n<h2>Method 2: The w Command<\/h2>\n<p>The w command provides information about the system&#8217;s current users and what they are doing, along with the server uptime. To use the w command, run:<\/p>\n<pre>\r\nw\r\n<\/pre>\n<p>The first line of the output displays the current time, system uptime, the number of users, and the load average, similar to the uptime command.<\/p>\n<pre> 23:06:57 up  1:38,  1 user,  load average: 0.00, 0.00, 0.00\r\nUSER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT\r\nroot     pts\/0    192.168.1.52     21:30    0.00s  1.85s  0.01s w\r\n<\/pre>\n<h2>Method 3: The top Command<\/h2>\n<p>The top command is a real-time system monitoring tool that provides an overview of the system&#8217;s processes and resource usage. It also displays the server uptime. To use the top command, run:<\/p>\n<pre>\r\ntop\r\n<\/pre>\n<p>The server uptime is displayed at the top of the output, next to the current time and the system load averages.<\/p>\n<pre> 23:27:01 up 4 days, 10:20,  1 user,  load average: 0.22, 0.12, 0.09\r\nTasks: 163 total,   1 running, 162 sleeping,   0 stopped,   0 zombie\r\n%Cpu(s):  6.1 us,  1.0 sy,  0.0 ni, 92.7 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st\r\nKiB Mem :  4043436 total,   282644 free,  1044916 used,  2715876 buff\/cache\r\nKiB Swap:  8388600 total,  8316440 free,    72160 used.  2905352 avail Mem\r\n<\/pre>\n<p>To exit the top command, press q.<\/p>\n<h2>Method 4: The \/proc\/uptime File<\/h2>\n<p>Linux stores the server uptime in seconds in the \/proc\/uptime file. You can check the contents of this file to determine the server&#8217;s uptime. To do this, run:<\/p>\n<pre>\r\ncat \/proc\/uptime\r\n<\/pre>\n<p>The output shows two values: the system uptime in seconds and the idle time in seconds. You can use awk to convert the uptime value to a more human-readable format:<\/p>\n<pre>\r\nawk '{print int($1\/86400)\" days \"int(($1%86400)\/3600)\" hours \"int(($1%3600)\/60)\" minutes\"}' \/proc\/uptime\r\n<\/pre>\n<p>This command will display the server uptime in days, hours, and minutes.<\/p>\n<h2>Method 5: The sysinfo Command (not available on all systems)<\/h2>\n<p>On some Linux distributions, you can use the sysinfo command to display various system information, including server uptime. To use the sysinfo command, run:<\/p>\n<pre>\r\nsysinfo\r\n<\/pre>\n<p>The server uptime is displayed in the output along with other system information.<\/p>\n<h2>Method 6: The who Command with -b Option<\/h2>\n<p>The who command can display various information about users on the system, but it also has a -b option that shows the last system boot time. To use the who command with the -b option, run:<\/p>\n<pre>\r\nwho -b\r\n<\/pre>\n<p>The output displays the last system boot time. You can calculate the server uptime by subtracting the boot time from the current time.<\/p>\n<h2>Method 7: The last Command with -x Option<\/h2>\n<p>The last command displays the history of user logins on the system. By using the -x option, you can also see information about system shutdowns and reboots. To use the last command with the -x option, run:<\/p>\n<pre>\r\nlast -x\r\n<\/pre>\n<p>Look for the most recent &#8220;system boot&#8221; entry in the output. This indicates the last time the system was rebooted, from which you can calculate the server uptime.<\/p>\n<h2>Method 8: Using systemd-analyze<\/h2>\n<p>For systems using systemd, you can use the systemd-analyze command to check the server uptime. To do this, run:<\/p>\n<pre>\r\nsystemd-analyze\r\n<\/pre>\n<p>The output displays the time elapsed since the last system boot. Note that this command may not be available on all Linux distributions.<\/p>\n<h3>Commands Mentioned:<\/h3>\n<ul>\n<li><span class=\"fw-bold\">uptime<\/span> &#8211; Displays system uptime, current time, the number of users, and the load average.<\/li>\n<li><span class=\"fw-bold\">w<\/span> &#8211; Provides information about the current users and their activity, along with system uptime and load average.<\/li>\n<li><span class=\"fw-bold\">top<\/span> &#8211; Monitors system processes and resource usage in real-time, and shows server uptime.<\/li>\n<li><span class=\"fw-bold\">cat \/proc\/uptime<\/span> &#8211; Displays the server uptime in seconds from the \/proc\/uptime file.<\/li>\n<li><span class=\"fw-bold\">sysinfo<\/span> &#8211; Shows various system information, including server uptime (not available on all systems).<\/li>\n<li><span class=\"fw-bold\">who -b<\/span> &#8211; Displays the last system boot time.<\/li>\n<li><span class=\"fw-bold\">last -x<\/span> &#8211; Shows the history of user logins, system shutdowns, and reboots.<\/li>\n<li><span class=\"fw-bold\">systemd-analyze<\/span> &#8211; Checks the server uptime on systems using `systemd` (may not be available on all Linux distributions).<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>In this guide, we have covered multiple methods for checking server uptime in Linux, including the uptime, w, top, \/proc\/uptime, sysinfo, who, last, and systemd-analyze commands. By using these tools, you can easily monitor your server&#8217;s uptime and ensure that it is running smoothly and reliably.<\/p>\n<p>Please feel free to leave comments and suggest improvements to this guide. Your feedback is valuable and helps us improve our content for our audience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Server uptime is an important metric that indicates how long a system has been running without interruption. In Linux, there are several commands that you can use to check server&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6823,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,996],"tags":[1536,1870],"class_list":["post-2089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-linux","tag-linux","tag-uptime"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/2089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=2089"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/2089\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6823"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=2089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=2089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=2089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}