Skip to Content

3 useful commands to check memory size in Linux

Do you ever wonder how much memory your system has? In Linux, there are a few different ways to check this information. In this blog post, we will discuss three commands that will help you get this data. These commands are “free,” “top,” and “cat /proc/meminfo.” Let’s take a look at each of them!

Understanding RAM in Linux

When it comes to understanding RAM in Linux, you first need to know about the different types of memory. There are three primary types of memory in a Linux system:

  • Physical Memory: This is the actual RAM installed in your system. It can be seen by running the “free” command.
  • Swap Space: This is an area on your hard drive that Linux can use as virtual memory. If your physical memory is full, Linux can move some data from physical memory to the swap space to make room. You can see how much swap space is available by running the “swapon” command.
  • Cache Memory: This is a type of memory used by the kernel to cache files and directories. It can be seen by running the “cat /proc/meminfo” command.

 

Understanding memory in Linux

Memory is important in Linux because it is used to store programs and data that are being used by the system. When the system needs more memory, it will start to page or swap out data that is not being used to make room for the new data. This can cause a decrease in system performance.

Check memory size with free command in Linux

The “free” command is probably the most popular way to check memory size in Linux. This command displays a summary of the system’s memory usage, including information on total, used, and free memory. To use this command, simply type “free” at the command prompt.

There are a few different options that you can use with the “free” command. For example, you can use the “-m” option to display the amount of memory in megabytes. To see a list of all of the available options, type “free –help” at the command prompt.

$ free -m
total    used    free   shared buff/cache  available
Mem:     31439    11243    12713      0    7482    20922
Swap:     3071      0    3071

Check memory size with top command in Linux

The “top” command is another way to check memory size in Linux. This command displays a list of all running processes, along with information on their CPU and memory usage. To use this command, simply type “top” at the command prompt.

Sort By memory Usage per-process in the interactive menu

  • press Shift+f to enter the interactive menu
  • press the up or down arrow until the %MEM choice is highlighted
  • press s to select %MEM choice
  • press enter to save your selection
  • press q to exit the interactive menu

 

Check memory size with cat /proc/meminfo command in Linux

The “cat /proc/meminfo” command can also be used to check memory size in Linux. This command displays a detailed list of all of the system’s memory information. To use this command, type “cat /proc/meminfo” at the command prompt.

To get the memory size from /proc/meminfo, you can use the “MemTotal,” “MemFree,” and “Used” fields. The “MemTotal” field shows the total amount of memory in the system, the “MemFree” field shows the amount of free memory in the system, and the “Used” field shows the amount of used memory in the system.

$ cat /proc/meminfo|grep MemTotal
MemTotal:    32193964 kB

So there you have it! Three different commands that you can use to check memory size in Linux. Do you have a favorite? Let us know in the comments below!