Skip to main content

Shell script for getting total amount of the system memory

In order to get total amount of the system memory as GigaByte in a bash script:

#!/bin/bash
mem_line=`cat /proc/meminfo |grep MemTotal`
mem_kb=`echo $mem_line | tr -cd '[[:digit:]]'`
mem_gb=$(awk "BEGIN{print $mem_kb/1024/1024}")
echo "System Memory (KB): "$mem_kb
echo "System Memory (GB): "$mem_gb

Comments

Popular posts from this blog

Find and replace with sed command in Linux

Find and replace feature is always handy. It can turn into a torture when it comes to change or delete a simple constant string in a text file. There is a handy tool in linux for doing these kind of tihngs. Actually sed is not a text editor but it is used outside of the text file to make changes.