How can I get CPU count and total RAM from the OS X command line?
Asked
Active
Viewed 9.8k times
3 Answers
89
You can get this from the system_profiler tool:
system_profiler SPHardwareDataType | grep " Memory:"
system_profiler SPHardwareDataType | grep Cores:
system_profiler SPHardwareDataType | grep Processors:
or, if you want to go low-level, use sysctl:
sysctl hw.memsize
sysctl hw.ncpu
Or to capture the values in a script (credit: @bleater):
mem_size=$(sysctl -n hw.memsize)
cpus_virtual=$(sysctl -n 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
Gordon Davisson
- 11,621
29
The following works in OS X Lion:
$ /usr/sbin/system_profiler SPHardwareDataType
Hardware:
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
stephen.z
- 501
8
scorp@antani-mac:~$ hwprefs cpu_count
2
scorp@antani-mac:~$ hwprefs memory_size
4.00 GB