Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get available memory in gb using single bash shell command

Tags:

linux

bash

shell

following command returns available memory in kilobytes

cat /proc/meminfo | grep MemFree | awk '{ print $2 }'

can some one suggest single command to get the available memory in gb?

like image 470
Haris Farooqui Avatar asked Jan 22 '16 01:01

Haris Farooqui


1 Answers

Just a slight modification to your own magical incantation:

awk '/MemFree/ { printf "%.3f \n", $2/1024/1024 }' /proc/meminfo

P.S.: Dear OP, if you find yourself invoking grep & awk in one line you're most likely doing it wrong ;} ... Same with invoking cat on a single file; that's hardly ever warranted.

like image 87
tink Avatar answered Oct 13 '22 04:10

tink