DEV Community

t-o-d
t-o-d

Posted on

3

Mac hardware and system information retrieval one-liner

  • 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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay