How to detect a Mac's model?

sysctl hw.model

04

Another way:

system_profiler SPHardwareDataType | grep "Model Identifier"

05

apple.stackexchange.com/a/98086