How to get the uptime from. The terminal. And in a bash file but only the uptime no other infomAtion

I would like it to be on one line


When in a terminal just run the following command.


This will display your current uptime plus a little ekstra information.

Mine says.

08:44:21 up 1:05, 2 users, load average: 0,00, 0,01, 0,05

So my uptime is 1 hour and 5 minutes. In a bash script to only get the uptime I'd use

uptime | awk '{print $3}'

This will show only the 3rd section of the uptime command.

| improve this answer | |
  • 1
    Be careful what the third section is. Since I have an uptime of '3 days, 1:41', I get just the number 3. – muru Dec 17 '14 at 11:46
  • Ah okay. Thought it was in the same column for displaying that. – Dan Johansen Dec 18 '14 at 11:52

Use echo $SECONDS , gives you the uptime of a terminal in seconds.

| improve this answer | |

You can also use the top command to know the uptime.


In the top of the terminal, you can view the uptime status.

| improve this answer | |
  • While this is true, it is a continuously ongoing command, so it's would not fit well with a bash script. – Dan Johansen Dec 17 '14 at 8:02
  • @DanJohansen top has a batch mode, which I'd say is meant for scripts. – muru Dec 17 '14 at 11:47
cat /proc/uptime | awk '{print $1}'

will give you the uptime expressed in seconds.

| improve this answer | |

This will show you when your system has booted and print uptime in brackets also:

last -x | grep boot | head -n 1 
| improve this answer | |

You can get the up time using different methods:

  • using w command

    $ w
    11:12:21 up 22:08,  3 users,  load average: 0.28, 0.32, 0.40

    If you just want the time nothing else:

    $ w | grep up | awk '{print $3}'
  • using uptime as described in other answer

  • using top as described in other answer

  • using utmp, you can see since when you are on:

    $ last utmp
    wtmp begins Mon Jun  1 08:29:04 2015

utmp maintains a full accounting of the current status of the system, system boot time (used by uptime), recording user logins at which terminals, logouts, system events.

| improve this answer | |
  • what is exactly utmp? Just curious because it shows me June 11th, it's like my computer hasn't been turned off since then? – JoKeR Jun 26 '15 at 8:29
  • 1
    Check the definition in the answer – Maythux Jun 26 '15 at 8:31
  • 1
    Indeed you use utmp in your answer :) last command read from utmp wtmp and btmp – Maythux Jun 26 '15 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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