Søren Lund (slu) wrote,
Søren Lund
slu

  • Mood:

How to check the amount of RAM in a Linux machine

On Linux information about memory are available ind the virtual file /proc/meminfo, you can open this file in an editor or simple display it in a console like this:

$ less /proc/meminfo


The output will be something like this:

MemTotal:      1034436 kB
MemFree:        296028 kB
Buffers:        108808 kB
Cached:         348964 kB
SwapCached:          0 kB
Active:         420868 kB
Inactive:       279276 kB
HighTotal:      129476 kB
HighFree:          252 kB
LowTotal:       904960 kB
LowFree:        295776 kB
SwapTotal:     1558264 kB
SwapFree:      1558264 kB
Dirty:             320 kB
Writeback:           0 kB
AnonPages:      242372 kB
...


Often you just want the amount of installed RAM, that's MemTotal. And you might also want it displayed as Mega og Giga Bytes. The following little awk-oneliner does that:

$ awk '/^MemTotal:/{d="kmg"; for (i=1; $2>999; i++) { $2/=1024 } print "RAM: " int($2+.5) substr(d,i,1) " B"}' /proc/meminfo
RAM: 1gB


If you're using bash, add the following to ~/.bashrc:

function raminfo {
  awk '/^MemTotal:/ {
                       d="kmg";
                       for (i=1; $2>999; i++) {
                         $2/=1024
                       }
                       print "RAM: " int($2+.5) substr(d,i,1) "B"
                    }' /proc/meminfo;
}


Now you can just use the raminfo function:

$ raminfo
RAM: 1gB
Tags: awk, bash, linux
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 2 comments