How to Check RAM/Memory by Percentage

Assalamualaikum,

Using the the free command:

This will report the percentage of memory in use
% free | grep Mem | awk '{print $3/$2 * 100.0}'
23.8171

This will report the percentage of memory that’s free
% free | grep Mem | awk '{print $4/$2 * 100.0}'
76.5013

You could create an alias for this command or put this into a tiny shell script. The specific output could be tailored to your needs using formatting commands for the print statement along these lines:
free | grep Mem | awk '{ printf("free: %.4f %\n", $4/$2 * 100.0) }'

wassalam..

Advertisements
This entry was posted in Linux and tagged , , , , . Bookmark the permalink.