理想未来ってなんやねん

娘可愛い。お父さん頑張る。

Macのシステム情報を取得するsystem_profilerコマンド

Macのお話。
system_profilerコマンドを使用するとシステム情報をテキストおよびXMLで取得できる。

$ system_profiler --help
Usage: system_profiler [-listDataTypes]
       system_profiler [-xml] [-detailLevel n]
       system_profiler [-xml] [dataType1 ... dataTypeN]

  -detailLevel n    specifies the level of detail for the report
                      mini = short report (contains no identifying or personal information)
                      basic = basic hardware and network information
                      full = all available information

  -listDataTypes    lists all the available datatypes

  -xml              generates xml output instead of plain text
                    if redirected to a file with the extension ".spx"
                    the file can be opened in System Profiler.app

Examples:

  system_profiler
     Generates a text report with the standard detail level.

  system_profiler -detailLevel mini
     Generates a short report without identifying/personal information.

  system_profiler -listDataTypes
     Shows a list of the available data types.

  system_profiler SPSoftwareDataType SPNetworkDataType
     Generates a text report containing only software and network data.

  system_profiler -xml >MySystem.spx
     Creates a XML file which can be opened by System Profiler.app


dataTypeを指定すると必要な情報のみ取得できる。指定しない場合、全ての情報を取得する。


例えば、dataTypeにSPHardwareDataTypeを指定すると、機種名、機種IDや搭載メモリ、二次キャッシュおよび三次キャッシュの容量やシリアル番号、ハードウェアUUIDなどを取得できる。

$ system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro8,2
      Processor Name: Intel Core i7
      Processor Speed: 2.2 GHz
      Number of Processors: 1
      Total Number of Cores: 4
      L2 Cache (per Core): 256 KB
      L3 Cache: 6 MB
      Memory: 16 GB
      Boot ROM Version: MBP81.0047.B24
      SMC Version (system): 1.69f3
      Serial Number (system): XXXXXXXXXXXX
      Hardware UUID: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
      Sudden Motion Sensor:
          State: Enabled

又、-xmlオプションを指定するとXMLで出力される。


dataTypeは、-listDataTypesオプションで取得できる。

$ system_profiler -listDataTypes
Available Datatypes:
SPParallelATADataType
SPApplicationsDataType
SPAudioDataType
SPBluetoothDataType
SPCardReaderDataType
SPComponentDataType
SPDeveloperToolsDataType
SPDiagnosticsDataType
SPDiscBurningDataType
SPEthernetDataType
SPExtensionsDataType
SPFibreChannelDataType
SPFireWireDataType
SPFirewallDataType
SPFontsDataType
SPFrameworksDataType
SPDisplaysDataType
SPHardwareDataType
SPHardwareRAIDDataType
SPNetworkLocationDataType
SPLogsDataType
SPManagedClientDataType
SPMemoryDataType
SPModemDataType
SPNetworkDataType
SPPCIDataType
SPParallelSCSIDataType
SPPowerDataType
SPPrefPaneDataType
SPPrintersSoftwareDataType
SPPrintersDataType
SPConfigurationProfileDataType
SPSASDataType
SPSerialATADataType
SPSoftwareDataType
SPStartupItemDataType
SPSyncServicesDataType
SPThunderboltDataType
SPUSBDataType
SPUniversalAccessDataType
SPNetworkVolumeDataType
SPWWANDataType
SPAirPortDataType


どのdataTypeを指定するとどのような情報が取得できるかについては、システム情報と見比べると大体わかると思う。