When using any Linux distribution, it is important as a SysAdmin to know how to visualize your available and used resources, such as memory, CPU, disk space, etc.
We have already showed you how to check CPU info in Linux, today, I am going to show how to check memory in Linux.
Note: Memory, physical memory terms are used for RAM (which is a more popular term). In other words, if you want to check RAM usage in Linux, you use the memory related commands. If you want to check disk space in Linux, you use disk related commands.
5 Commands to check memory usage in Linux
In this article, we will cover how to check memory in different ways and explain a little bit how each of the command lines for this purpose works.
The free command in Linux has the simplest output. It shows the amount of free and used memory on your Linux system.
You can see the free and used physical memory i.e. RAM, the swap usage and the buffer used by the Linux kernel.
All you have to do is to type free in the terminal and hit enter:
You can see that the free command provides only the necessary info at a glance.
This is probably one of the most common and the one that I use at first. It gives the information about memory and CPU. Here is a screenshot of how it looks:
In the header you will notice how it reports the total amount of memory, the amount used and the amount free, and this for both regular (RAM) memory and SWAP memory as well. It also gives you a real time visualization of the current running processes and the amount each one is consuming.
You can press Shift+M keys to sort top command on memory usage.
htop is very similar in functionality to the top command, yet it’s slightly different. It is a bit more graphical and shows information a little more friendlier than top, however, it is also a real time visualization:
You can see the used memory out of the available memory beside the Mem line on the top left section.
Even though it might seem like we are consulting a file, in reality whatever in contained inside “proc” folder is just virtual files that display information directly from kernel.
This one method gives you very detailed information about the memory, not only a general view but even the amount of pages of memory being used.
You can use any file viewing Linux command to display the content of the file. I have used cat command in my example below.
Explaining in deep all this information would require an entire article so I am not going to to do that here.
5. vmstat -m
Like the /proc/meminfo, this one gives you information directly from kernel, in fact, only a superuser can execute it (so if you are running a Debian or Ubuntu based, you will need to sudo it).
It gives you a very in deep detail about the memory available and the pages of memory being used:
Bonus: RAM information with dmidecode
Dmidecode is more about the memory chip physically, it gives information about the actual chips allocated in your computer, so it allows you to know more things about the current installed memory such as: where is it physically located (which memory bank), what type of memory is it (DIMM, SIMM), speed, manufacturer, voltage and even if any error is currently being detected.
Running it as: sudo dmidecode -t 17 will give you information similar to this screenshot:
As usual, Linux offers you several ways to consult information about something, in this case checking memory usage in your system. This information depending for what is needed and how it’s used can be very useful and provide valuable information as SysAdmin.