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)
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)
To get the time elapsed since last system boot in
hh:mm:ss
format, you can use:/proc/uptime
pseudo-file contains two numbers:So, using
awk
you can take firs number and convert it inhh:mm:ss
format.To get uptime in seconds:
To get uptime in minutes:
To get uptime in hours:
To get x digits of precision you can add scale=x, e.g. for x=2
Try this one:
In fact, it prints the third word of the line produced by
uptime
.A trivial modification to show days:
figured I'd add mine to the collection since there's nothing similar...
tried to be more efficient with mine:
result:
42d 17h 23m 55s
EDIT: since I realized I didn't quite answer the original question, here's a revision specifically for that:
result:
17:23:55
This will format your output as 2 zero padding:
As an addition to @realmoonstruck answer:
You could do this solely in awk which saves you one pipe and the subsequent call of
bc
.To get the uptime in minutes:
For simple metrics, I sometimes just want an INT of the hours:
NOTE: You could '+ 1' to round up to the nearest full hour
A further trivial modification for layout:
Example Output:
Format [dddd:hh:mm:ss]
Sample: 0122:05:14:03