How to Check RAM Size Using CLI?

RAM is the abbreviation of ”Random Access Memory” and is the basic part of the computer that stores data temporarily. It is based on volatile nature means that data will be lost when the user turns off or restarts the operating system. 

Linux supports various tools through which users can check the size of the RAM. The RAM size is determined in order to check that the system has enough memory to run applications or if there are any performance issues in the system. 

This post will enlighten the various ways to check the RAM size in Linux.

Method 1: Using /proc/meminfo File to Check RAM Size

The “/proc/meminfo” is the file that contains the report of the memory usage of the system such as total memory, swap memory, or available memory. The user can analyze this file to check the total RAM size of the operating system by displaying its content using the “cat” utility: 

$ cat /proc/meminfo

The file has printed the report of the RAM usage and the total memory size is “1987192 kB” which is approximately equal to 1.9GB. While the free memory is “75508 KB”.

Method 2: Using free Utility to Check RAM Size

In Linux, “free” is the built-in utility that is utilized for displaying the used physical and swap memory usage in the operating system. Use the free command with the “h” flag for displaying the output in human-readable format:

$ free -h

The total, used, free, shared, buff/cache, and available memory sizes are “1.9GB”, “1.5GB”, “65MB”, “11MB”, “311MB”, and “200MB”.

Likewise, the user can use the “s” flag to specify the time interval in seconds, and it will display the memory usage detail after every particular second. The following command will display the memory result after every 3 seconds:

$ free -h -s 3

The user can stop the above process by pressing “Ctrl+C”.

Method 3: Using top Utility to Check RAM Size

Another way to check the RAM size is by using the top utility, which is used for displaying real-time process information related to Kernel. Run the top command in the terminal to get the memory information:

$ top

The total memory is size 1940.6MB, and the swapped memory is 923.2MB. The other free, used, cache memory and available memory can also be seen in the image.

Method 4: Using vmstat Utility to Check RAM Size

The vmstate is a utility that generates the memory statistics results such as paging, CPU, and memory utilization. Run the “vmstat” command with the “s” flag to display statistics:

$ vmstat -s

The memory information, such as total, used, active, inactive, and buffer, can be seen in the above image.

Method 5: Using dmidecode Utility to Check RAM Size

Another method to get RAM information is using the “dmidecode” utility, which displays the computer hardware component’s information. In most of the Linux distributions, it is pre-installed but can be installed through the given command if not found:

$ sudo apt install dmidecode        #For Debian/Ubuntu
$ sudo yum install dmidecode        #For CentOS/RHEL
$ sudo dnf install dmidecode        #For Fedora
$ sudo pacman -S dmidecode          #For Arch

To display the memory-specific information using “dmidecode” utility, use the “type” flag with number 19 because the memory information starts with the number 19:

$ sudo dmidecode --type 19

The RAM size is 2GB can be seen in the above image.

Method 6: Using lshw Utility to Check RAM Size

To display the memory information through the “lshw” utility. For this, specify the memory class using the “C” flag and the grep command to match the particular row of ‘System Memory’:

$ sudo lshw -C memory -short | grep 'System Memory'

The RAM size “2GB” has been shown in the above image.

Method 7: Using hwinfo Utility to Check RAM Size

The RAM size can also be checked using the “hwinfo” command that displays the hardware information. The “hwinfo” command can be installed using the below command:

$ sudo apt install hwinfo       #For Debian/Ubuntu
$ sudo dnf install hwinfo       #For CentOS/RHEL
$ sudo dnf install hwinfo       #For Fedora

To display memory information, use the hwinfo command with the “memory” option as follows:

$ hwinfo --memory

The Memory size is “1GB + 896 MB” which is equal to 1.9GB.

Conclusion

To check the RAM size in Linux, utilize the “/proc/meminfo” file, “free”, “top”, “vmstat”, “dmidecode”, “lshw”, or “hwinfo” utilities. The user can check the memory, such as total, swapped, cache, buffer/cache, or available memory. This write-up has illustrated various methods to check the RAM size in Linux.