The "free" tool that is standard on most *NIX (Unix and Linux, but apparently not yet on Mac OSX) doesn't give you a quick report of how much is truly free. You need to take into account free buffers. See the awk command below for a quick-and-dirty way to get a reasonable estimate of the percent of memory that is free: $ free total used free shared buffers cached Mem: 16431244 16172416 258828 0 149172 8336852 -/+ buffers/cache: 7686392 8744852 Swap: 8388592 5959752 2428840 $ free | grep "buffers/cache" | awk '{print $4/($3+$4) * 100}' 53.2152 Note that the "free buffers/cache" value on the second line is the sum of the free+buffers+cached values on the first line. And free+used buffers is equal to the total memory on the first line. So you only need those two values on the second line to do all the math. Another way is to grep these values out of first 4 lines of /proc/meminfo and do the math like this: (MemFree + Buffers + Cached) / MemTotal = %used $ cat /proc/meminfo | head -4 MemTotal: 16431244 kB MemFree: 286180 kB Buffers: 149776 kB Cached: 8340288 kB So: (286180 + 149776 + 8340288) / 16431244 = 8776244 / 16431244 = 0.53412, or 53.412% free |
Linux >