Convert linux uptime to well format date

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to convert uptime to date DD:MM:YY without the | and I want to put a string like "the computer is on since 23-feb-16"
linux shell-script date uptime
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I want to convert uptime to date DD:MM:YY without the | and I want to put a string like "the computer is on since 23-feb-16"
linux shell-script date uptime
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
do you likeuptime -p?
– Jeff Schaller
Nov 20 at 21:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to convert uptime to date DD:MM:YY without the | and I want to put a string like "the computer is on since 23-feb-16"
linux shell-script date uptime
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to convert uptime to date DD:MM:YY without the | and I want to put a string like "the computer is on since 23-feb-16"
linux shell-script date uptime
linux shell-script date uptime
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 20 at 21:40
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 20 at 21:19
ZPUFF19
33
33
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
ZPUFF19 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
do you likeuptime -p?
– Jeff Schaller
Nov 20 at 21:29
add a comment |
1
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
do you likeuptime -p?
– Jeff Schaller
Nov 20 at 21:29
1
1
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
do you like
uptime -p ?– Jeff Schaller
Nov 20 at 21:29
do you like
uptime -p ?– Jeff Schaller
Nov 20 at 21:29
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
You may get it for free from the output of last reboot:
$ last reboot
reboot system boot 4.14.81-i7 Sat Nov 17 23:25 still running
reboot system boot 4.14.80-i7 Fri Nov 16 09:16 - 15:49 (06:33)
$ printf "On since: "; last reboot | grep "still running" | cut -c 40-56
On since: Sat Nov 17 23:25
$ printf "On since: " ; last reboot --time-format iso | grep "still running" | cut -c 40-49
On since: 2018-11-17
Your uptime command might also have the -s option:
$ uptime -s
2018-11-17 23:25:23
Since this format is acceptable to date -d, you can reformat the time however you wish like this::
$ date -d "$(uptime -s)" "+On since: %d:%m:%y"
On since: 17:11:18
add a comment |
up vote
2
down vote
Single command.
$ date -r /proc/1 '+The computer is on since %d-%b-%y'
The computer is on since 09-Oct-18
$
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You may get it for free from the output of last reboot:
$ last reboot
reboot system boot 4.14.81-i7 Sat Nov 17 23:25 still running
reboot system boot 4.14.80-i7 Fri Nov 16 09:16 - 15:49 (06:33)
$ printf "On since: "; last reboot | grep "still running" | cut -c 40-56
On since: Sat Nov 17 23:25
$ printf "On since: " ; last reboot --time-format iso | grep "still running" | cut -c 40-49
On since: 2018-11-17
Your uptime command might also have the -s option:
$ uptime -s
2018-11-17 23:25:23
Since this format is acceptable to date -d, you can reformat the time however you wish like this::
$ date -d "$(uptime -s)" "+On since: %d:%m:%y"
On since: 17:11:18
add a comment |
up vote
2
down vote
accepted
You may get it for free from the output of last reboot:
$ last reboot
reboot system boot 4.14.81-i7 Sat Nov 17 23:25 still running
reboot system boot 4.14.80-i7 Fri Nov 16 09:16 - 15:49 (06:33)
$ printf "On since: "; last reboot | grep "still running" | cut -c 40-56
On since: Sat Nov 17 23:25
$ printf "On since: " ; last reboot --time-format iso | grep "still running" | cut -c 40-49
On since: 2018-11-17
Your uptime command might also have the -s option:
$ uptime -s
2018-11-17 23:25:23
Since this format is acceptable to date -d, you can reformat the time however you wish like this::
$ date -d "$(uptime -s)" "+On since: %d:%m:%y"
On since: 17:11:18
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You may get it for free from the output of last reboot:
$ last reboot
reboot system boot 4.14.81-i7 Sat Nov 17 23:25 still running
reboot system boot 4.14.80-i7 Fri Nov 16 09:16 - 15:49 (06:33)
$ printf "On since: "; last reboot | grep "still running" | cut -c 40-56
On since: Sat Nov 17 23:25
$ printf "On since: " ; last reboot --time-format iso | grep "still running" | cut -c 40-49
On since: 2018-11-17
Your uptime command might also have the -s option:
$ uptime -s
2018-11-17 23:25:23
Since this format is acceptable to date -d, you can reformat the time however you wish like this::
$ date -d "$(uptime -s)" "+On since: %d:%m:%y"
On since: 17:11:18
You may get it for free from the output of last reboot:
$ last reboot
reboot system boot 4.14.81-i7 Sat Nov 17 23:25 still running
reboot system boot 4.14.80-i7 Fri Nov 16 09:16 - 15:49 (06:33)
$ printf "On since: "; last reboot | grep "still running" | cut -c 40-56
On since: Sat Nov 17 23:25
$ printf "On since: " ; last reboot --time-format iso | grep "still running" | cut -c 40-49
On since: 2018-11-17
Your uptime command might also have the -s option:
$ uptime -s
2018-11-17 23:25:23
Since this format is acceptable to date -d, you can reformat the time however you wish like this::
$ date -d "$(uptime -s)" "+On since: %d:%m:%y"
On since: 17:11:18
edited Nov 20 at 21:36
answered Nov 20 at 21:26
telcoM
14.5k11842
14.5k11842
add a comment |
add a comment |
up vote
2
down vote
Single command.
$ date -r /proc/1 '+The computer is on since %d-%b-%y'
The computer is on since 09-Oct-18
$
add a comment |
up vote
2
down vote
Single command.
$ date -r /proc/1 '+The computer is on since %d-%b-%y'
The computer is on since 09-Oct-18
$
add a comment |
up vote
2
down vote
up vote
2
down vote
Single command.
$ date -r /proc/1 '+The computer is on since %d-%b-%y'
The computer is on since 09-Oct-18
$
Single command.
$ date -r /proc/1 '+The computer is on since %d-%b-%y'
The computer is on since 09-Oct-18
$
answered Nov 20 at 21:57
steve
13.8k22452
13.8k22452
add a comment |
add a comment |
ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.
ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.
ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.
ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483061%2fconvert-linux-uptime-to-well-format-date%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What is the output of your uptime command? What distro are you using? On Ubuntu, uptime outputs something like "16:25:06 up 47 days, 8:50, 2 users, load average: ..." The "16:25:06" is the time. The "up 47 days, 8:50" is up 47 days, 8 hours and 50 minutes" So, are you wanting to do a date/time calculation on the "47 days, 8:50" or is the output of your uptime different? Could you edit your question to show the output of the uptime command you are using?
– Lewis M
Nov 20 at 21:28
do you like
uptime -p?– Jeff Schaller
Nov 20 at 21:29