Introduction
Sometimes Memory Usage monitoring in Linux might be tricky. In this Blog, we will learn about the basic linux commands that you as an Linux user will find these commands very useful and so that you can run the same during day to day operations.
By executing a few basic commands on the terminal, you can obtain all the necessary information and track memory statistics to enhance the performance of your Linux system. Below are the list of command that we will go through in detail in this blog:
- cat
- free
- vmstat
- top
These commands are compatible with almost all Linux distributions, and we will provide an explanation of their functions and how to interpret the output.
cat Command to Show Linux Memory Information
Entering cat /proc/meminfo
in your terminal opens the /proc/meminfo file.
This virtual file provides real-time information on the available and used memory, as well as kernel buffers. It is important to note that the output may vary slightly depending on the architecture and operating system being used.
free Command to Display the Amount of Physical and Swap Memory
Typing free
in your command terminal provides the following result:
total | Total installed memory |
used | Memory currently in use by running processes (used= total – free – buff/cache) |
free | Unused memory (free= total – used – buff/cache) |
shared | Memory shared by multiple processes |
buffers | Memory reserved by the OS to allocate as buffers when process need them |
cached | Recently used files stored in RAM |
buff/cache | Buffers + Cache |
available | Estimation of how much memory is available for starting new applications, without swapping. |
The free
command has multiple options to format the output so that it better matches your requirements. The table below lists the most useful variations of the free
command.
Options | Result |
-b | output in bytes |
-k | output in kibibytes |
-m | output in mebibytes |
-g | output in gibibytes |
-l | detailed low and high memory statistics |
-o | old format (no -/+buffers/cache line) |
-t | total for RAM + swap |
-s | update every [delay] seconds |
-c | update [count] times |
vmstat Command to Report Virtual Memory Statistics
vmstat
provides general information about processes, memory, paging, block IO, traps, and CPU activity.
top Command to Check Memory Use
The top
command is useful to check memory and cpu usage per process. It displays information about:
- uptime
- average load
- tasks running
- number of users logged in
- number of CPUs/CPU utilization
- memory/swap system processes
Note: If you want to change the delay for top command output then use cmd +d
and specify the number in seconds. Below is the sample output of top command.
Conclusion
The guide presented various approaches for monitoring memory usage on Linux. One of the commands discussed provides a significant amount of valuable information that can be reviewed later. It’s crucial to learn how to interpret this information accurately.
You can now manage your server more efficiently.
Hope it helps. Cheers!!!