- When I use Mac, there are times when I want to get system information and so on by command.
- Also, you may want to use that information in shellscript.
- In this article, we will write commands to obtain hardware and system information from your Mac.
Result
- Here are the results.
- Enter each command based on the information you want to retrieve.
Model Name
# model name # output : MacBook Pro** info=$(system_profiler SPHardwareDataType | grep 'Model Identifier'); echo "${info#*: }"
Processor
# processor # output : Dual-Core Intel ** info=$(system_profiler SPHardwareDataType | grep 'Processor Name'); echo "${info#*: }"
Core
# core # output : 2 info=$(system_profiler SPHardwareDataType | grep 'Cores'); echo "${info#*: }"
Serial Number
# serial number # output : ***** info=$(system_profiler SPHardwareDataType | grep 'Serial Number'); echo "${info#*: }"
UUID
# UUID # output : *****-*****-**** info=$(system_profiler SPHardwareDataType | grep 'UUID'); echo "${info#*: }"
Memory
# memory information # output : ** GB info=$(system_profiler SPHardwareDataType | grep 'Memory'); echo "${info#*: }"
User
# user information # output : **** *** (*******) info=$(system_profiler SPSoftwareDataType | grep 'User Name'); echo "${info#*: }"
Supplement
- For ease of use, the fetched content only outputs the results.
- Use shall be in the following format.
info=$(system_profiler data-type-name | grep 'field-name'); echo "${info#*: }"
- The above data-type-name and field-names are confirmed by the following command.
- data-type-name :
system_profiler -listDataTypes
- field-name :
system_profiler data-type-name
- Other information that can be obtained with system_profiler can be found here.
Link
Top comments (0)