slu

Søren's Blog

Random Ramblings

Previous Entry Share Next Entry
How to check the amount of RAM in a Linux machine
slu
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: , ,

  • 1
sudo lshw -short -class memory

Re: Perhaps use lshw

Great. That gives more precise information about the specific type of RAM installed. It does require sudo to give that info though.

  • 1
?

Log in

No account? Create an account