9

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 3

3

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
1

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.

1

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:

https://apple.stackexchange.com/questions/4286/is-there-a-mac-os-x-terminal-version-of-the-free-command-in-linux-systems

2
  • Thanks, that's close, the other question has some good suggestions.
    – jimbo
    Dec 19, 2012 at 20:53
  • That is absolutely not correct. Executing that would try to execute /mem/, which is nonsense, after successful pipeline evaluation. Did you mean sysctl -a | awk '/hw\.mem/' ? Jan 26 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .