Human readable system memory reading from CLI?

If that's all you need, just use free:

$ free -h | gawk  '/Mem:/{print $2}'
7.8G

free returns memory info, the -h switch tells it to print in human readable format.


On Linux,

read x memtotal x < /proc/meminfo

Would store the total mem amount in $memory in number of kiB. That's the amount of memory available to Linux, the same as reported by free.

If you want the installed RAM, you could do things like:

awk '{s+=$0};END{print s}' /sys/bus/mc*/devices/dimm*/size

To get the size in MiBs. Or

awk '{s+=$0};END{printf "%.2gG\n", s/1024}' /sys/bus/mc*/devices/dimm*/size

If you want the size in GiB.