We have a Linux machine with 32G. We capture the mem as follows:
mem=` cat /proc/meminfo | grep MemTotal | awk '{print $2}' `
echo $mem
32767184
and now we convert it to GIGA:
mem_in_giga=` echo $(( $mem / 1024 / 1024)) `
echo $mem_in_giga
31
but from the results we get 31 and not 32G.
The same story with the free command:
free -g
total used free shared buff/cache available
Mem: 31 9 17 0 4 20
Swap: 7 0 7
So how do we get "32G" from any command?
32:echo $((32767184/1000/1000)). – muru Feb 01 '18 at 12:39free -goutputs gibibytes, all the values quoted from output in the question are gibibytes. That’s appropriate since RAM capacities are bought in gibibyte or tebibyte increments... – Stephen Kitt Feb 01 '18 at 12:53cat,grep, andecho:awk '$1 == "MemTotal:" { print $2 / 1024 / 1024 }' /proc/meminfo– phemmer Feb 01 '18 at 13:20