Command to display free memory in percentage
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
add a comment |
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
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
shell-script awk
edited Dec 29 '18 at 17:12
valiano
202111
202111
asked Dec 29 '18 at 9:34
User101User101
584
584
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
add a comment |
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
);
);
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%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
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
add a comment |
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
add a comment |
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
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
answered Dec 29 '18 at 13:26
msp9011msp9011
3,82843863
3,82843863
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Dec 29 '18 at 11:45
answered Dec 29 '18 at 11:12
Chris SmithChris Smith
564
564
add a comment |
add a comment |
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.
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%2f491433%2fcommand-to-display-free-memory-in-percentage%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