When working on performance optimization or system monitoring, knowing your Mac's hardware specs is essential. Here are the most efficient terminal commands:
To get the number of physical CPU cores:
sysctl -n hw.physicalcpu
For logical processors (including hyper-threading):
sysctl -n hw.logicalcpu
To get detailed CPU architecture information:
sysctl -n machdep.cpu.brand_string
For total installed RAM in bytes:
sysctl -n hw.memsize
Convert to human-readable GB format:
echo $(( $(sysctl -n hw.memsize) / 1073741824 )) GB
For a more comprehensive hardware report:
system_profiler SPHardwareDataType
Sample output (truncated):
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro18,3
Chip: Apple M1 Pro
Total Number of Cores: 10 (8 performance and 2 efficiency)
Memory: 32 GB
Create this function in your .bash_profile for quick checks:
function sysinfo() {
echo "CPU: $(sysctl -n machdep.cpu.brand_string)"
echo "Cores: $(sysctl -n hw.physicalcpu) physical, $(sysctl -n hw.logicalcpu) logical"
echo "RAM: $(( $(sysctl -n hw.memsize) / 1073741824 )) GB"
}
For scripting purposes, here's how to extract just the memory value:
system_profiler SPHardwareDataType | awk '/Memory/ {print $2,$3}'
These commands execute differently:
sysctl
- Instant (~0.001s)
system_profiler
- Slower (~1-2s) but more detailed
When developing performance-sensitive applications or troubleshooting system issues, knowing your hardware specs is crucial. Here are the most efficient terminal commands for macOS:
sysctl -n hw.ncpu
# Returns just the number of active CPU cores
# Example output: 8
For more detailed CPU architecture information:
sysctl -n machdep.cpu.brand_string
# Example output: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
sysctl -n hw.memsize
# Returns RAM in bytes (divide by bytes for GB)
# Example output: 17179869184 (16GB)
For human-readable output:
system_profiler SPHardwareDataType | grep "Memory"
# Example output: Memory: 16 GB
Create an alias for quick system checks:
alias sysinfo='echo "CPU Cores: $(sysctl -n hw.ncpu)" & echo "RAM: $(($(sysctl -n hw.memsize)/1024/1024/1024)) GB"'
# Usage: sysinfo
# Example output:
# CPU Cores: 8
# RAM: 16 GB
For developers needing more detailed hardware information:
system_profiler SPHardwareDataType
# Provides comprehensive hardware report including:
# - Processor details
# - Memory configuration
# - Serial numbers
# - Boot ROM version
For script-friendly JSON output (macOS 10.10+):
system_profiler SPHardwareDataType -json
# Returns machine-readable JSON format
These commands are particularly useful for:
- Build system configuration scripts
- Docker container resource allocation
- Performance benchmarking tools
- System requirement validation
Remember that virtualized environments might report different values than physical hardware.