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.
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.
In top, memory is displayed in “MiB” or mebibytes. 1 mebibyte equals 1,048,576 bytes, which is 1024 x 1024 bytes.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With