DEV Community

loading...

Mac hardware and system information retrieval one-liner

kamekuremaisuke profile image t-o-d ・1 min read
  • 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#*: }"
Enter fullscreen mode Exit fullscreen mode

Processor

# processor
# output : Dual-Core Intel **
info=$(system_profiler SPHardwareDataType | grep 'Processor Name'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

Core

# core
# output : 2
info=$(system_profiler SPHardwareDataType | grep 'Cores'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

Serial Number

# serial number
# output : *****
info=$(system_profiler SPHardwareDataType | grep 'Serial Number'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

UUID

# UUID
# output : *****-*****-****
info=$(system_profiler SPHardwareDataType | grep 'UUID'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

Memory

# memory information
# output : ** GB
info=$(system_profiler SPHardwareDataType | grep 'Memory'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

User

# user information
# output : **** *** (*******)
info=$(system_profiler SPSoftwareDataType | grep 'User Name'); echo "${info#*: }"
Enter fullscreen mode Exit fullscreen mode

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

Discussion (0)

pic
Editor guide