Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display /proc/meminfo into Megabytes

Tags:

shell

unix

I want to thank you for helping me my related issue. I know if i do a cat /proc/meminfo it will only display in kb how can i display in mb ? I really want to use cat or awk for this please.

like image 870
javanoob17 Avatar asked Apr 23 '15 00:04

javanoob17


People also ask

What is the output of cat Proc Meminfo?

On Linux you can use the command cat /proc/meminfo to determine how much memory the computer has. This command displays the information stored in the meminfo file located in the /proc directory. The total amount of memory will be displayed as MemTotal, shown in the example in bold.

What is the unit of memory in top?

In top, memory is displayed in “MiB” or mebibytes. 1 mebibyte equals 1,048,576 bytes, which is 1024 x 1024 bytes.


1 Answers

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
like image 168
John1024 Avatar answered Sep 22 '22 18:09

John1024