Search code examples
shellopenwrtuptimeash

How to modify the uptime command on shell?


When I type in uptime in terminal it gives me something like this

 16:44:17 up  7:50,  load average: 0.31, 0.47, 0.54

I want to make it to be something like this

Uptime: 7h 50m
Load average: 0.31, 0.47, 0.54

and save it to uptime.txt

How can I do that? I'm sorry for the dumb question, I'm still new in this and I've googled before but I find nothing useful.


Solution

  • this ugly command will work:

    uptime | sed 's#[0-9][0-9]:[0-9][0-9]:[0-9][0-9]##g' | sed 's#:#h #g' | sed -E 's#, [^,]+users,#m#g' | sed 's/ days,/d/g'|sed 's/  up/Uptime:/g' | sed 's/load averageh/\nLoad average:/g'