How can I get the total physical memory in bytes of my Linux PC?
I need to assign it to a bash script variable
Thanks in advance
How can I get the total physical memory in bytes of my Linux PC?
I need to assign it to a bash script variable
Thanks in advance
grep MemTotal /proc/meminfo | awk '{print $2}'
The returned number is in KB
phymem=$(awk -F":" '$1~/MemTotal/{print $2}' /proc/meminfo )
or using free
phymem=$(free|awk '/^Mem:/{print $2}')
or using shell
#!/bin/bash
while IFS=":" read -r a b
do
case "$a" in
MemTotal*) phymem="$b"
esac
done <"/proc/meminfo"
echo $phymem