If you're logged in at some remote Linux system and need to quickly confirm the amount of available memory, there's a few commands you will find quite useful.
free – free and used memory stats
free command is the most obvious choice for a first command when it comes to your RAM.
Simply run it without any parameters, and it will show you something like this:
ubuntu# free total used free shared buffers cached Mem: 4051792 4024960 26832 0 63768 3131532 -/+ buffers/cache: 829660 3222132 Swap: 4096492 43212 4053280
For this exercise, you're only interested in the "total" column of the first line. 4051792 confirms that my home PC seems to have around 4Gb of memory available for Ubuntu to use.
Using dmesg to check memory size as recognized by Linux kernel
dmesg command shows you the last status messages reported by your OS kernel, and since every boot procedure includes scanning the hardware and confirming the devices and resources recognized by the kernel, you can see some basic information by using dmesg.
For our purpose, we need to filter out the memory stats:
ubuntu# dmesg | grep Memory [ 18.617904] Memory: 4043492k/5242880k available (2489k kernel code, 150360k reserved, 1318k data, 320k init)
Once again, the overall amount of memory confirms that 4Gb of RAM were still found during the last time my PC booted up.
Using /proc/meminfo to confirm the RAM size
/proc/meminfo is one of the special files managed by Linux kernel. It's a clear text presentation of the most vital memory stats of your system (this means you can do something like cat /proc/meminfo to see all the parameters)
This is what you need to do to get the total size of your physical memory:
ubuntu# grep MemTotal /proc/meminfo MemTotal: 4051792 kB
That's it for today, enjoy!