Often times you want to know how much RAM or memory is installed on your machine and how much of it is currently being used. This is especially useful if you find that your machine is acting sluggish or crashing repeatedly. It can also come in handy after you have upgraded the memory on your machine, you want to make sure that the new memory is getting used.
There are several methods in Linux or Unix machines to determine how much RAM or memory you have installed on your machine. Though most of these commands are available across different and all Posix platforms, some are also dependent on the Linux distributions and what libraries or packages you have installed on the system.
We will primarily use the command shell in this post to find the memory usage. IMHO, This is probably also the quickest and easiest method to use. There are also a couple of GUI options depending on your distro. Many people may find the GUI based option much more user friendly to use. We will mostly concentrate on the command line options in this post.
You can use the free command to find almost all information about the RAM or memory usage and availability. There are several command line options available with this command to print the information in bytes, kilobytes, megabytes or gigabytes. –human (or -h) will print the output in human readable format, while –total (or -t) will add a row which totals the columns.
bash$ free -ht
There is also the option to print out the lowest and highest memory usage statistics using the command line option -l.
bash$ free -htl
Another way to find the available memory is using the top command. Though primarily used to display process information, it also displays some information about the installed RAM (random access memory) or the memory. Look for information at the top of the output, where it says KiB Mem which displays the total available memory on the system.
Another option is to check the kernel ring buffer output to see what the kernel detected during the system startup about the installed memory. This information is printed out with a line prefix Memory. So, the following command will print out the memory information…
bash$ dmesg | grep Memory
will output something like
Memory: 6156316k/7012352k available (4648k kernel code, 63836k reserved, 2402k data, 424k init, 5307208k highmem)
The first part of the output is the value that you are looking for. The memory info is usually printed out in kB or kilo bytes. You can easily convert it to the metric you want.
Apart from the free and top command, most modern Linux distros also have a GUI option (actually there might be several) that shows the entire system information including the installed memory.
In Gnome, gnome-system-monitor will show you the memory usage and the total memory installed on the system. You can access this from a terminal by the command gnome-system-monitor or access it from the menu, look for a menu entry by the name of System Monitor.
In KDE, the equivalent GUI option is ksysguard. Again you can access it by the command ksysguard at the command prompt or look for it in the KDE menu by the name of System Monitor.
Though all of the above commands and programs will give you detailed information about the memory and its status on your system, that is not all you can find. You can find a plethora of information about your installed memory from the process file meminfo. If you are just looking to find the total memory installed on your system, then this might actually be an overkill.
bash$ cat /proc/meminfo
As you can see there is lot of information in the output, actually way more than what the above screenshot shows. It shows information about the Swap, Memory, High and Low totals, Active and Inactive files, Dirty Pages, Huge Page information and much much more. It is very unlikely that you will need all of these information. You are most likely looking for first three or four rows of this table.
You can use the grep command to narrow or filter the output down to the memtotal row (or a set of rows), which shows you the total installed memory on your system. As with almost all other commands, you can use grep as in this example.
bash$ grep -i memtotal /proc/meminfo
The above command or example will just print out the field MemTotal from the output, which is the total memory that is installed in the system. You can use other filter text such as mem, or total to print out the rows selectively.
No matter which command you use, the info about the RAM or memory that is printed out should match or should be similar across all of them.