In Linux cat /proc/meminfo | grep MemTotal
gets back MemTotal: 12298824 kB
I want only the numbers here
so i wrote cat /proc/meminfo | grep MemTotal | cut -d':' -f2
which gave me 12298824 kB
I only want the numbers here, can anyone help me?
Note: cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | cut -d'k' -f1
gives me the solution 12298824
, but is there a better way? one liner?
Use awk:
cat /proc/meminfo | grep MemTotal | awk '{print $2}'
From @Lars Wirzenius's comment(No cat
and No grep
):
awk '/MemTotal/ { print $2 }' /proc/meminfo
I have used:
dmidecode -t 17 | grep Size | awk '{s+=$2} END {print s}'
to great effect in my CentOS kickstart %pre section. It returns the total installed amount of memory in MB. Even if you have empty memory banks, awk will ignore them and only add the integer results.
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