Friday, May 3, 2024
42
rated 0 times [  42] [ 0]  / answers: 1 / hits: 61578  / 2 Years ago, sat, june 18, 2022, 9:43:50

I want to display the time elapsed since last system boot using uptime, but I don't want it to display all that info. I just want to know how many hours passed since last system boot (i.e. : 18:17:59)


More From » command-line

 Answers
7

To get the time elapsed since last system boot in hh:mm:ss format, you can use:



awk '{print int($1/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime


/proc/uptime pseudo-file contains two numbers:




  • 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.



So, using awk you can take firs number and convert it in hh:mm:ss format.


[#29836] Saturday, June 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
laiuct

Total Points: 44
Total Questions: 105
Total Answers: 107

Location: Seychelles
Member since Mon, Feb 15, 2021
3 Years ago
;