Reputation: 12347
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?
Upvotes: 6
Views: 11290
Reputation: 21
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.
Upvotes: 2
Reputation: 63708
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
Upvotes: 16