Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
up vote 8 down vote accepted

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.

share|improve this answer

To get uptime in seconds:

awk '{print $1}' /proc/uptime

To get uptime in minutes:

 echo $(awk '{print $1}' /proc/uptime) / 60 | bc

To get uptime in hours:

 echo $(awk '{print $1}' /proc/uptime) / 3600 | bc

To get x digits of precision you can add scale=x, e.g. for x=2

echo "scale=2; $(awk '{print $1}' /proc/uptime) / 3600" | bc
share|improve this answer

Try this one:

uptime | awk '{ print $3 }'

In fact, it prints the third word of the line produced by uptime.

share|improve this answer
It works. But it doesn't seems the right way to do it. What if the third word isn't the time, for example my third word is "4" , because my machine is running for 4 days. This is what I get: "02:00:39 up 4 days, 12:54, 2 users, load average: 0.03. 0.06, 0.06" . – Adrian George Aug 21 '13 at 23:03
Oh :D I didn’t know about the time more than 1 day! – AliNa Aug 21 '13 at 23:45
It ok :d now you have some answers to this? – Adrian George Aug 21 '13 at 23:47
No, sorry. uptime seems to have no options but I couldn’t find anything on the net either. – AliNa Aug 22 '13 at 0:04

A trivial modification to show days:

awk '{print int($1/86400)"days "int($1%86400/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.