brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: sysctl -n machdep.cpu.brand_string names the chip in your Mac

macOS
~/tips/tip-macos-sysctl-cpu-brand-memsize

sysctl -n machdep.cpu.brand_string hw.memsize hw.ncpu

Print the chip name, memory size and core count with one short command.

When a forum asks which Mac you have, or a script needs to know how many cores it can use, I don’t want to click through About This Mac. sysctl reads it straight from the kernel.

The -n flag prints only the values, without the names in front, so the output is easy to use in a script. You can ask for several keys at once:

sysctl -n machdep.cpu.brand_string hw.memsize hw.ncpu

On an Apple silicon Mac the first line is the chip, for example Apple M5 Pro. The second is the installed memory in bytes, and the third the number of CPU cores the system reports.

Bytes are not very readable, so turn the memory into gigabytes with a bit of shell arithmetic:

echo $(( $(sysctl -n hw.memsize) / 1073741824 )) GB

That’s the kind of line I’d put in a setup script that picks a number of parallel jobs, or in a bug report template.

The caveat is that keys differ per machine and per macOS version, and a key that doesn’t exist just gives an error. To see what your Mac offers, list everything and filter it, for example sysctl -a | grep hw.perflevel, which on Apple silicon shows the performance and efficiency core groups separately. The sysctl man page also notes that only the superuser can change values; reading them is harmless.

Further reading: sysctl.8 man page, sysctl.3 man page

More macOS tips System Settings > Accessibility > Hover Text > When using the pointer A Smart Folder in Notes collects notes by tag, checklist or date Type # in a Mac note to tag it, then filter by tag in the sidebar tmutil isexcluded ~/Projects/app/node_modules Crop an image in Preview by dragging a frame and clicking Crop All macOS tips (99) All topics

Link