用 sysctl 读取 Mac 硬件信息
从内核 sysctl 树获取 CPU 型号、核心数、内存大小和启动参数等内核状态。
运行 `sysctl -n machdep.cpu.brand_string` 查 CPU 型号,`sysctl hw.ncpu` 查核心数,`sysctl hw.memsize` 查内存字节数。
01命令
命令
$ sysctl -n machdep.cpu.brand_string && sysctl -n hw.ncpu && sysctl -n hw.memsize02作用说明
sysctl 以命名树的形式暴露内核状态:`hw.*` 是硬件清单,`machdep.*` 是 CPU 详情,`kern.*` 是启动参数和限制。`-n` 只输出值本身,非常适合脚本——比如用 `sysctl -n hw.ncpu` 决定构建的并行度。Apple Silicon 机型还能用 `hw.perflevel*` 查看性能核与能效核的划分。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- SYSCTL Command: Get or set the kernel state in macOS依据: Documents sysctl -a listing, -n value-only output, and the hw/machdep kern trees.
最后验证: 2026-09-17 · 分类: 系统与设置