'How to change this code /proc/meminfo from kb to mb/gb?
I got right now this in the code
`cat /proc/meminfo |
grep MemFree |
awk {'print $2'}`kB (Free) / `cat /proc/meminfo |
grep MemTotal |
awk {'print $2'}`kB (Total)
Solution 1:[1]
Not exactly what do you ask for but also worth to consider:
free -h
free -h --mega
Solution 2:[2]
grep MemFree /proc/meminfo
output: MemFree: 15932276 kB
echo $(expr $(awk '/MemFree/{ print $2 }' /proc/meminfo) / 1)
output: 15932268
echo $(expr $(awk '/MemFree/{ print $2 }' /proc/meminfo) / 1024) Mb
output: 15558 Mb
echo $(expr $(awk '/MemFree/{ print $2 }' /proc/meminfo) / 1024 / 1024) Gb
output: 15 Gb
- see man expr
- Also you used backquotes around a statement. It better to use
$(...)(The best reason is that it will not interfere with stackoverflow formatting ?)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex Cumarav |
| Solution 2 |
