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