Any command to list the memory in MB rather than kB from /proc/meminfo?

Cat, less , more , head tail etc. tried with all options that I am aware of. Can't find how to list the memory in Megabytes rather than kB.

2 Answers

Can't find how to list the memory in Megabytes rather than kB.

This will convert any kB lines to MB:

awk '$3=="kB"{$2=$2/1024;$3="MB"} 1' /proc/meminfo | column -t

This version converts to gigabytes:

awk '$3=="kB"{$2=$2/1024**2;$3="GB";} 1' /proc/meminfo | column -t

For completeness, this will convert to MB or GB as appropriate:

awk '$3=="kB"{if ($2>1024**2){$2=$2/1024**2;$3="GB";} else if ($2>1024){$2=$2/1024;$3="MB";}} 1' /proc/meminfo | column -t

Source How to display /proc/meminfo into Megabytes, answer by John1024

3

In bash you may do it this way

#! /bin/bash
kb-to-mb()
{ echo $1" "$(( $2 / 1024))" "MB
}
exec < /proc/meminfo
while read a b c
do if [ o$c = "okB" ] then kb-to-mb $a $b $c else echo $a $b $c kb-to-mb $a $b $c
done | column -t
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like