How to get macOS CPU details information in the command line All In One
How to get macOS CPU details information in the command line All In One
如何通过
命令行
获取 macOSCPU
的详细信息
bug ❌
无法获取具体 CPU 版本
型号
,如 CPU 是第几代i7
3.2 GHz 6-Core Intel Core i7
❓
solutions
sysctl
🚀
Intel(R) Core(TM)
i7-8700B
CPU @ 3.20GHz
$ sysctl
usage: sysctl [-bdehiNnoqx] name[=value] ...
sysctl [-bdehNnoqx] -a
# CPU 具体型号
$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
$ sysctl -a | grep machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
# CPU
$ sysctl -a | grep machdep.cpu
- Node.js
os
module ✅
// .mjs
import os from 'node:os'
// const os = require('node:os');
// console.log(`os =`, os)
// console.log(`os.arch =`, os.arch)
/* os.arch = [Function: arch] {
[Symbol(Symbol.toPrimitive)]: [Function (anonymous)]
} */
console.log(`os.arch() =`, os.arch())
console.log(`os.cpus() =`, os.cpus())
console.log(`os.cpus().length =`, os.cpus().length)
console.log(`os.cpus()[0] =`, os.cpus()[0])
console.log(`os.hostname() =`, os.hostname())
console.log(`os.platform() =`, os.platform())
console.log(`os.userInfo() =`, os.userInfo())
console.log(`os.version() =`, os.version())
// console.log(`os =`, os)
'Intel(R) Core(TM)
i7-8700B
CPU @ 3.20GHz ✅
$ node ./get-cpu-info.mjs
os.arch() = x64
os.cpus() = [
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 35793980, nice: 0, sys: 20182000, idle: 305512840, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 420630, nice: 0, sys: 554650, idle: 361714780, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 31032440, nice: 0, sys: 14759860, idle: 315670380, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 423540, nice: 0, sys: 542910, idle: 361727940, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 26214970, nice: 0, sys: 11853140, idle: 323740060, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 434690, nice: 0, sys: 537270, idle: 361727810, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 22187320, nice: 0, sys: 9764620, idle: 330060780, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 436720, nice: 0, sys: 511270, idle: 361754380, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 17329330, nice: 0, sys: 7251480, idle: 337660770, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 432550, nice: 0, sys: 480450, idle: 361789130, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 14743530, nice: 0, sys: 6103380, idle: 341523160, irq: 0 }
},
{
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 413560, nice: 0, sys: 440150, idle: 361858230, irq: 0 }
}
]
os.cpus().length = 12
os.cpus()[0] = {
model: 'Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz',
speed: 3200,
times: { user: 35793980, nice: 0, sys: 20182000, idle: 305512840, irq: 0 }
}
os.hostname() = xgqfrms-mm.local
os.platform() = darwin
os.userInfo() = {
uid: 501,
gid: 20,
username: 'xgqfrms-mm',
homedir: '/Users/xgqfrms-mm',
shell: '/bin/zsh'
}
os.version() = Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
- npm
package
$ npm i -D systeminformation
const os = require('systeminformation');
// promises style - new since version 3
os.cpu()
.then(data => console.log(data))
.catch(error => console.error(error));
https://www.npmjs.com/package/systeminformation
https://systeminformation.io/cpu.html
- Linux
/proc/cpuinfo
# macOS 不好使 ❌
$ cat /proc/cpuinfo
system_profiler
❓
$ system_profiler
$ system_profiler > system_profiler.md
# 具体 CPU 型号信息隐藏了/加密了 💩
$ system_profiler | grep Processor
# $ system_profiler | grep Hardware
# Hardware:
Hardware Overview:
Model Name: Mac mini
Model Identifier: Macmini8,1
Processor Name: 6-Core Intel Core i7 # ❌
Processor Speed: 3.2 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
System Firmware Version: 1968.120.12.0.0 (iBridge: 20.16.5060.0.0,0)
OS Loader Version: 577~170
Serial Number (system): C07ZC0VTJYVY
Hardware UUID: FBE6D95A-0137-5929-904A-867894A0C40A
Provisioning UDID: FBE6D95A-0137-5929-904A-867894A0C40A
Activation Lock Status: Enabled
demos
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
https://www.cnblogs.com/xgqfrms/p/17400616.html
https://apple.stackexchange.com/a/352770/346428
https://osxdaily.com/2011/07/15/get-cpu-info-via-command-line-in-mac-os-x/
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17774047.html
未经授权禁止转载,违者必究!