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.
uptime
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.
You can also use the top command to know the uptime.
top
In the top of the terminal, you can view the uptime status.
cat /proc/uptime | awk '{print $1}'
will give you the uptime expressed in seconds.
This will show you when your system has booted and print uptime in brackets also:
last -x | grep boot | head -n 1
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}'
22:08,
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.