sysctl hw.model
Another way:
system_profiler SPHardwareDataType | grep "Model Identifier"
apple.stackexchange.com/a/98086