linux get memory usage code example

Example 1: linux memory usage

// linux command for reporting used memory percentage
$ free | grep Mem | awk '{print $3/$2 * 100.0}'
23.8171

Example 2: Ram usage in linux

$ cat /proc/meminfo

Example 3: linux command to check memory usage in percentage

$ free -t | awk 'NR == 2 {printf("Current Memory Utilization is : %.2f%"), $3/$2*100}'
or
$ free -t | awk 'FNR == 2 {printf("Current Memory Utilization is : %.2f%"), $3/$2*100}'

Current Memory Utilization is : 20.42%