Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get CPU count and total RAM from the OS X command line?

share|improve this question
up vote 11 down vote accepted
scorp@antani-mac:~$ hwprefs cpu_count
scorp@antani-mac:~$ hwprefs memory_size
4.00 GB
share|improve this answer
hwprefs doesn't seem to be part of the default OS X install (I think it's in Xcode, or maybe the CHUD tools). – Gordon Davisson Feb 16 '10 at 4:50
hwprefs: command not found on Mac Os x Lion – aleroot Nov 6 '11 at 10:20

You can get this from the system_profiler tool:

system_profiler | grep "  Memory:"
system_profiler | grep Cores:
system_profiler | grep Processors:

or, if you want to go low-level, use sysctl:

sysctl hw.memsize
sysctl hw.ncpu

btw, there are a bunch of other interesting things you can get from sysctl. Try:

sysctl -a | grep cpu

to see a few of them

share|improve this answer
+1: The sysctl method works on Mountain Lion. – Warren Young Feb 28 '13 at 16:44
To capture the output of sysctl in a script, use the -n option, e.g. sh/bash script: CPUS_VIRTUAL=`sysctl -n hw.ncpu` – bleater Oct 8 '13 at 2:51
+1: systemctl works best on 10.11.x – Danijel-James W Apr 20 at 5:16

The following works in OS X Lion:

$ /usr/sbin/system_profiler SPHardwareDataType


    Hardware Overview:

      Model Name: iMac
      Model Identifier: iMac7,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.4 GHz
      Number of Processors: 1
      Total Number of Cores: 2
      L2 Cache: 4 MB
      Memory: 4 GB
      Bus Speed: 800 MHz
share|improve this answer
This was the most useful one for me since I got everything I was looking for from one command, and works on the recovery terminal for Yosemite (10.10). – Aaron R. Nov 24 '14 at 17:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.