Command to display free memory in percentage

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














I want to display free memory as a percentage. I'm pretty sure that I'm not displaying the free memory but the used one. Or am I wrong?



mem=`free -m | awk 'NR ==2printf $3,$2,$3*100/$2'`
echo $mem









share|improve this question




























    1














    I want to display free memory as a percentage. I'm pretty sure that I'm not displaying the free memory but the used one. Or am I wrong?



    mem=`free -m | awk 'NR ==2printf $3,$2,$3*100/$2'`
    echo $mem









    share|improve this question


























      1












      1








      1







      I want to display free memory as a percentage. I'm pretty sure that I'm not displaying the free memory but the used one. Or am I wrong?



      mem=`free -m | awk 'NR ==2printf $3,$2,$3*100/$2'`
      echo $mem









      share|improve this question















      I want to display free memory as a percentage. I'm pretty sure that I'm not displaying the free memory but the used one. Or am I wrong?



      mem=`free -m | awk 'NR ==2printf $3,$2,$3*100/$2'`
      echo $mem






      shell-script awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 29 '18 at 17:12









      valiano

      202111




      202111










      asked Dec 29 '18 at 9:34









      User101User101

      584




      584




















          2 Answers
          2






          active

          oldest

          votes


















          1














          Try this,



          free | awk '/^Mem/ a=(($3-$7)/$2 * 100); print a"% of Memory used" '
          3.43143% of Memory used

          free | awk '/^Mem/ a=(($4+$7)/$2 * 100); print a"% of Memory free" '
          96.5662% of Memory free

          free | awk '/^Mem/ a=(($7)/$2 * 100); print a"% of Memory cached" '
          80.4204% of Memory cached


          Note: crosscheck the values with glances






          share|improve this answer




























            2














            If you want to display the amount of free memory as a percentage, Divide Column 4 (free) by Column 2 (total) and multiply the result by 100.



            For example:



            [user@localhost ~]$ free | awk '/^Mem/ printf("free: %.2f %n", $4/$2 * 100.0) '
            free: 97.32 %


            If you want to show the amount used, you can divide column 3 (used) by column 2 (total) and multiply the result by 100.



            [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.2f %n", $3/$2 * 100.0) '
            Used: 2.75 %


            You can use %g for rounding to a specified number of significant digits.



            For example, if you only want a whole number, and not a floating point value, you can change the number of floating point digits specified to 0 (zero). In this first example %.2f means 2 floating point values.



            And here is an example with zero floating point values:



            [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.0f %n", $3/$2 * 100.0) '
            Used: 3 %


            This is also answered here:



            https://stackoverflow.com/questions/10585978/linux-command-for-percentage-of-memory-that-is-free






            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',
              autoActivateHeartbeat: false,
              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
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491433%2fcommand-to-display-free-memory-in-percentage%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









              1














              Try this,



              free | awk '/^Mem/ a=(($3-$7)/$2 * 100); print a"% of Memory used" '
              3.43143% of Memory used

              free | awk '/^Mem/ a=(($4+$7)/$2 * 100); print a"% of Memory free" '
              96.5662% of Memory free

              free | awk '/^Mem/ a=(($7)/$2 * 100); print a"% of Memory cached" '
              80.4204% of Memory cached


              Note: crosscheck the values with glances






              share|improve this answer

























                1














                Try this,



                free | awk '/^Mem/ a=(($3-$7)/$2 * 100); print a"% of Memory used" '
                3.43143% of Memory used

                free | awk '/^Mem/ a=(($4+$7)/$2 * 100); print a"% of Memory free" '
                96.5662% of Memory free

                free | awk '/^Mem/ a=(($7)/$2 * 100); print a"% of Memory cached" '
                80.4204% of Memory cached


                Note: crosscheck the values with glances






                share|improve this answer























                  1












                  1








                  1






                  Try this,



                  free | awk '/^Mem/ a=(($3-$7)/$2 * 100); print a"% of Memory used" '
                  3.43143% of Memory used

                  free | awk '/^Mem/ a=(($4+$7)/$2 * 100); print a"% of Memory free" '
                  96.5662% of Memory free

                  free | awk '/^Mem/ a=(($7)/$2 * 100); print a"% of Memory cached" '
                  80.4204% of Memory cached


                  Note: crosscheck the values with glances






                  share|improve this answer












                  Try this,



                  free | awk '/^Mem/ a=(($3-$7)/$2 * 100); print a"% of Memory used" '
                  3.43143% of Memory used

                  free | awk '/^Mem/ a=(($4+$7)/$2 * 100); print a"% of Memory free" '
                  96.5662% of Memory free

                  free | awk '/^Mem/ a=(($7)/$2 * 100); print a"% of Memory cached" '
                  80.4204% of Memory cached


                  Note: crosscheck the values with glances







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 29 '18 at 13:26









                  msp9011msp9011

                  3,82843863




                  3,82843863























                      2














                      If you want to display the amount of free memory as a percentage, Divide Column 4 (free) by Column 2 (total) and multiply the result by 100.



                      For example:



                      [user@localhost ~]$ free | awk '/^Mem/ printf("free: %.2f %n", $4/$2 * 100.0) '
                      free: 97.32 %


                      If you want to show the amount used, you can divide column 3 (used) by column 2 (total) and multiply the result by 100.



                      [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.2f %n", $3/$2 * 100.0) '
                      Used: 2.75 %


                      You can use %g for rounding to a specified number of significant digits.



                      For example, if you only want a whole number, and not a floating point value, you can change the number of floating point digits specified to 0 (zero). In this first example %.2f means 2 floating point values.



                      And here is an example with zero floating point values:



                      [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.0f %n", $3/$2 * 100.0) '
                      Used: 3 %


                      This is also answered here:



                      https://stackoverflow.com/questions/10585978/linux-command-for-percentage-of-memory-that-is-free






                      share|improve this answer



























                        2














                        If you want to display the amount of free memory as a percentage, Divide Column 4 (free) by Column 2 (total) and multiply the result by 100.



                        For example:



                        [user@localhost ~]$ free | awk '/^Mem/ printf("free: %.2f %n", $4/$2 * 100.0) '
                        free: 97.32 %


                        If you want to show the amount used, you can divide column 3 (used) by column 2 (total) and multiply the result by 100.



                        [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.2f %n", $3/$2 * 100.0) '
                        Used: 2.75 %


                        You can use %g for rounding to a specified number of significant digits.



                        For example, if you only want a whole number, and not a floating point value, you can change the number of floating point digits specified to 0 (zero). In this first example %.2f means 2 floating point values.



                        And here is an example with zero floating point values:



                        [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.0f %n", $3/$2 * 100.0) '
                        Used: 3 %


                        This is also answered here:



                        https://stackoverflow.com/questions/10585978/linux-command-for-percentage-of-memory-that-is-free






                        share|improve this answer

























                          2












                          2








                          2






                          If you want to display the amount of free memory as a percentage, Divide Column 4 (free) by Column 2 (total) and multiply the result by 100.



                          For example:



                          [user@localhost ~]$ free | awk '/^Mem/ printf("free: %.2f %n", $4/$2 * 100.0) '
                          free: 97.32 %


                          If you want to show the amount used, you can divide column 3 (used) by column 2 (total) and multiply the result by 100.



                          [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.2f %n", $3/$2 * 100.0) '
                          Used: 2.75 %


                          You can use %g for rounding to a specified number of significant digits.



                          For example, if you only want a whole number, and not a floating point value, you can change the number of floating point digits specified to 0 (zero). In this first example %.2f means 2 floating point values.



                          And here is an example with zero floating point values:



                          [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.0f %n", $3/$2 * 100.0) '
                          Used: 3 %


                          This is also answered here:



                          https://stackoverflow.com/questions/10585978/linux-command-for-percentage-of-memory-that-is-free






                          share|improve this answer














                          If you want to display the amount of free memory as a percentage, Divide Column 4 (free) by Column 2 (total) and multiply the result by 100.



                          For example:



                          [user@localhost ~]$ free | awk '/^Mem/ printf("free: %.2f %n", $4/$2 * 100.0) '
                          free: 97.32 %


                          If you want to show the amount used, you can divide column 3 (used) by column 2 (total) and multiply the result by 100.



                          [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.2f %n", $3/$2 * 100.0) '
                          Used: 2.75 %


                          You can use %g for rounding to a specified number of significant digits.



                          For example, if you only want a whole number, and not a floating point value, you can change the number of floating point digits specified to 0 (zero). In this first example %.2f means 2 floating point values.



                          And here is an example with zero floating point values:



                          [user@localhost ~]$ free | awk '/^Mem/ printf("Used: %.0f %n", $3/$2 * 100.0) '
                          Used: 3 %


                          This is also answered here:



                          https://stackoverflow.com/questions/10585978/linux-command-for-percentage-of-memory-that-is-free







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 29 '18 at 11:45

























                          answered Dec 29 '18 at 11:12









                          Chris SmithChris Smith

                          564




                          564



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491433%2fcommand-to-display-free-memory-in-percentage%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

                              How to check contact read email or not when send email to Individual?

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay