I'm used to typing free -m
in ubuntu to see how much memory is available, in MB. What's the equivalent command in Mac OSX?
3 Answers
As of 2022, I'd propose this, which I tested on bash and zsh, on Mac 12.2.1:
echo $(( $(sysctl -a | awk '/memsize/{print $2}') / 2**30 ))
Explanation:
$(( ... )) arithmetic expansion (allows integer math)
awk '/memsize/' search for memsize in the output
{print $2} of the output, only print the second "column" of output, i.e., the number
/ 2**30 divide the result by 2 to the 30th power, 1,073,741,824 (i.e., 1 GB)
Result on my 16GB Mac:
16
should be :
sysctl -a | awk '/hw./' && '/mem/'
(note the '/mem/'
)
then run the output through egrep
(depending upon what is desired).
There are some perl
scripts too - on the net.
Since OS X is BSD-based, your best bet will be using sysctl
to get the information you need.
sysctl -a | awk '/hw./' && '/mem/'
You could also try this:
-
-
That is absolutely not correct. Executing that would try to execute
/mem/
, which is nonsense, after successful pipeline evaluation. Did you meansysctl -a | awk '/hw\.mem/'
? Jan 26 at 11:05