Convert linux uptime to well format date

The name of the pictureThe name of the pictureThe name of the pictureClash 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"










share|improve this question









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 like uptime -p ?
    – Jeff Schaller
    Nov 20 at 21:29














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"










share|improve this question









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 like uptime -p ?
    – Jeff Schaller
    Nov 20 at 21:29












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"










share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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 like uptime -p ?
    – Jeff Schaller
    Nov 20 at 21:29












  • 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







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










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





share|improve this answer





























    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
    $





    share|improve this answer




















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.









       

      draft saved


      draft discarded


















      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

























      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





      share|improve this answer


























        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





        share|improve this answer
























          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





          share|improve this answer














          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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 at 21:36

























          answered Nov 20 at 21:26









          telcoM

          14.5k11842




          14.5k11842






















              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
              $





              share|improve this answer
























                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
                $





                share|improve this answer






















                  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
                  $





                  share|improve this answer












                  Single command.



                  $ date -r /proc/1 '+The computer is on since %d-%b-%y'
                  The computer is on since 09-Oct-18
                  $






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 21:57









                  steve

                  13.8k22452




                  13.8k22452




















                      ZPUFF19 is a new contributor. Be nice, and check out our Code of Conduct.









                       

                      draft saved


                      draft discarded


















                      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.













                       


                      draft saved


                      draft discarded














                      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





















































                      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






                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)