How can I find out the total physical memory (RAM) of my linux box suitable to be parsed by a shell script?

前端 未结 13 1791
梦如初夏
梦如初夏 2020-12-07 09:52

I\'m typing a shell script to find out the total physical memory in some RHEL linux boxes.

First of all I want to stress that I\'m interested in the total ph

相关标签:
13条回答
  • 2020-12-07 10:00
    dmidecode -t 17 | grep  Size:
    

    Adding all above values displayed after "Size: " will give exact total physical size of all RAM sticks in server.

    0 讨论(0)
  • 2020-12-07 10:00

    I find htop a useful tool.

    sudo apt-get install htop

    and then

    free -m

    will give the information you need.

    0 讨论(0)
  • 2020-12-07 10:06
    free -h | awk '/Mem\:/ { print $2 }' 
    

    This will provide you with the total memory in your system in human readable format and automatically scale to the appropriate unit ( e.g. bytes, KB, MB, or GB).

    0 讨论(0)
  • 2020-12-07 10:07

    If you're interested in the physical RAM, use the command dmidecode. It gives you a lot more information than just that, but depending on your use case, you might also want to know if the 8G in the system come from 2x4GB sticks or 4x2GB sticks.

    0 讨论(0)
  • 2020-12-07 10:07

    Add the last 2 entries of /proc/meminfo, they give you the exact memory present on the host.

    Example:

    DirectMap4k:       10240 kB
    DirectMap2M:     4184064 kB
    

    10240 + 4184064 = 4194304 kB = 4096 MB.

    0 讨论(0)
  • 2020-12-07 10:07

    One more useful command:
    vmstat -s | grep memory
    sample output on my machine is:

      2050060 K total memory
      1092992 K used memory
       743072 K active memory
       177084 K inactive memory
       957068 K free memory
       385388 K buffer memory
    

    another useful command to get memory information is:
    free
    sample output is:

                 total       used       free     shared    buffers     cached
    Mem:       2050060    1093324     956736        108     385392     386812
    -/+ buffers/cache:     321120    1728940
    Swap:      2095100       2732    2092368
    

    One observation here is that, the command free gives information about swap space also.
    The following link may be useful for you:
    http://www.linuxnix.com/find-ram-details-in-linuxunix/

    0 讨论(0)
提交回复
热议问题