Linux: Get Memory percentages.

PHOTO EMBED

Mon Aug 29 2022 14:15:24 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #bash

#This will report the percentage of memory in use

% free | grep Mem | awk '{print $3/$2 * 100.0}'

#Ex:23.8171

#This will report the percentage of memory that's free

% free | grep Mem | awk '{print $4/$2 * 100.0}'

#Ex: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) }'
content_copyCOPY