Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know some of you might find my question stupid but i need to know how much ram is installed on a centos box Yes i know it can easily be done by using the command

awk '/MemTotal/{print $2}' /proc/meminfo

However the problem is that the memory shown is not really want i need.The value shown will always be less than expected as some ram is used to load the kernel.Thus a 512 MB ram server will always show a little less than 524288 kb.

The reason while i need the full physical ram is very simple.I need to modify settings automatically on a box via my bash script. Thus if server has total 512 MB ram , one set of setting is used , if 1gb then another.....

I cannot gamble with the value return by the command above as value varies from system to system.

Any good valid option guys.......

Kind Regards

share|improve this question
I know comparison with bash ...question is not about bash command here.I need an ssh commmand that can get me the true physical ram installed on server – Werulz Mar 6 '13 at 17:22
up vote 4 down vote accepted

Here you go... From my larger script at: Documenting server details

# Calculate installed RAM
dmidecode -t 17 | awk '( /Size/ && $2 ~ /^[0-9]+$/ ) { x+=$2 } END{ print "\t" "Installed Ram: " x "MB"}'

Output: Installed Ram: 28672MB (or divide by 1024)

share|improve this answer
Thanks so much.However i need to installed dmidecode then...i though it could be without any 3rd party.Dude can you modify the command so that it output only 28672 and not "Installed Ram:" and MB(its for convenience.... – Werulz Mar 6 '13 at 17:28
I haven't learn awk yet , i know only sed for now....regards ewwhite – Werulz Mar 6 '13 at 17:33
@Werulz dmidecode -t 17 | awk '( /Size/ && $2 ~ /^[0-9]+$/ ) { x+=$2 } END{ print x }' – ewwhite Mar 6 '13 at 17:36
Bro i have a little question about your command.It may happen that dmidecode contain Size multiple times like in… .Do the command automatically add all values of "Size"....Thanks – Werulz Mar 7 '13 at 5:09
@Werulz Yes. That's what happens. – ewwhite Mar 7 '13 at 12:31

Unfortunately, dmidecore requires root privileges.

Another way to retrieve values, more accurate than MemTotal in /proc/meminfo :

$ dmesg | gawk '/BIOS-e820/&&/usable/{tot+=strtonum("0x"$4)-strtonum("0x"$2)}END{print "Total RAM: "tot/1048576" MB"}'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.