Introduction
This is another article regarding on how to retrieve the valuable information from a machine. The information in the context of this article is about the total memory of a machine. The total memory is actually the physical memory. There are several ways in order to get the information about the total physical memory in a machine. In this article, in order to get the total physical memory of a machine is by executing a certain command in the command line interface. The command execution is a command mainly exist or available in the Linux family operating system distribution.
/proc/meminfo
Using the correct command for retrieving the suitable information, the total physical memory will be available. It exist in the file with the name of ‘meminfo’. It exist in a folder in the location of ‘/proc’. The file containing the information about the memory is the ‘meminfo’ file. There are lots of command available for modifying the information in the file of ‘/proc/meminfo’. One of the command available for retrieving the suitable information is using ‘awk’. The following is the usage example :
user@hostname:~$ awk '/MemTotal/ {print $2 / (1024*1024) " GB"}' /proc/meminfo 15.4324 GB user@hostname:~$
The above command is the complete form resulting on the information of memory size in GB. The following is the modification of the command from the simple one into the complete form :
awk '/MemTotal/' /proc/meminfo
The following is the output of the above command execution :
user@hostname:~$ awk '/MemTotal/' /proc/meminfo MemTotal: 16182084 kB user@hostname:~$
The execution of the above command will result on one line containing string of ‘MemTotal’. There are two columns in that one row. The first one is only a string of ‘MemTotal’. The next column is the size of the memory itself. In other words, there is no need to print the first column. Just print the second column. So, a change in the command is a must. The following is the command modification :
user@hostname:~$ awk '/MemTotal/ {print $2}' /proc/meminfo 16182084 kB user@hostname:~$
In order to print the size of the memory into Gigabyte metric, there is a need to modify the command. The following is that command modification :
user@hostname:~$ awk '/MemTotal/ {print $2 / (1024 * 1024)}' /proc/meminfo 15.4324 user@hostname:~$
In order to complete the output of the result, add another string after it. Just add the ‘GB’ string in the end of it. Below is the complete modification of the command :
user@hostname:~$ awk '/MemTotal/ {print $2 / (1024 * 1024) " GB"}' /proc/meminfo 15.4324 GB user@hostname:~$