The virtual memory of a computer is a priority resource and as such must be controlled and monitored properly with the tools that we offer you. That includes knowing how to see memory RAM used and the one that is free, as well as the exchange memory itself or SWAP, which stores all the data and processes that are not a priority and have not been uploaded to RAM or have been extracted from it to introduce others with higher priority. Well, this is a simple explanation of how it would work, without going into much detail.
To know how to control or, rather, monitor these memories In our Linux system, there are numerous possibilities. It is possible to do it directly by viewing with the concatenator some of the files of the /proc interface that Linux provides or use the tools that we are going to mention that can use this type of files or others to obtain said information and present it in a more user-friendly way. tidy. You can even use commands like top and others referring to processes that provide certain data about the memory...First let's go with the free command, with it you can see the used and free RAM and SWAP memory, buffer, etc. For this you can also use the -h option that shows the units in a somewhat more understandable way in my opinion:
free -h
With the command swapon We can activate partitions or swap files, but with the -s option we can also see its capacity:
swapon -s
We continue with vmstat which, as its name suggests, shows the status of virtual memory:
vmstat
Another option would be memstat, similar to the previous one:
memstat
Let's go now with the / proc files that we can consult to obtain memory info:
cat /proc/swaps
cat /proc/meminfo
And finally we are going to make use of another command, which simply uses the DMI tables to obtain hardware information, in this case filtering only the memory information using this option:
sudo dmidecode --type memory
Interesting article.
The grace is to combine it with watch to monitor every several seconds (by default 2 but can be adjusted with "-n").
Examples:
watch free -h
watch -n 1 free -h
Another utility that Bash offers us is to execute commands at the same time with the operators "&&" and ";"
Example:
free -h; cat / proc / swaps
It can also be filtered using grep and the use of a pipe ("|" character).
Example:
free -h | grep 'Memory'
Or even add the text we want using printf
printf 'My command: \ n'; free -h
And much more 🙂