命令行获取 mac os x 系统信息

如果你在Mac 中 处于不能访问 图形界面的情况下,例如 只能在通过 SSH 访问,而此时你需要获取一些系统信息, 使用 OS X 内置的 Terminal,你同样可以获取到你需要的系统信息。

sw_vers

sw_vers 命令:获取当前Mac 操作系统 版本号和编译版本号.

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.5
BuildVersion:	16F73

uname

uname 命令能够读取到Mac 操作系统的信息。最佳使用格式为 uname -a

$ uname -a
Darwin hostname.fqdn 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

system_profiler

system_profiler 命令是一个命令行接口 (CLI) 由 System Profiler 应用提供,Mac 内置了该应用。 当你没有权限访问GUI时,可以通过它来读取系统信息。

$ system_profiler

system_profiler 输出的信息量让它显得毫无用处,除非你知道你正在查找什么信息 。以下为有效使用 system_profiler 的方法:

detailLevel

system_profiler 命令 提供了 3 种 不同级别的报告模式: minibasicfull

  • system_profiler -detailLevel mini: 将会生成一个不包含个人信息及认证信息的系统信息文本报告。
  • system_profiler -detailLevel basic: 本命令生成仅包含基本硬件和网络信息的报告。
  • system_profiler -detailLevel full: 生成系统所有信息报告。
dataType

使用带有 -detailLevel 参数 的 system_profiler 可以根据具体情况选择不同的模式,但这绝不是 system_profiler 的终极威力,我们可以使用带有数据类型的命令模式。

传入参数 -listDataTypes 可以获取到当前支持的数据类型。

$ system_profiler -listDataTypes

以下为可用 数据类型:

  • SPParallelATADataType
  • SPUniversalAccessDataType
  • SPApplicationsDataType
  • SPAudioDataType
  • SPBluetoothDataType
  • SPCameraDataType
  • SPCardReaderDataType
  • SPComponentDataType
  • SPDeveloperToolsDataType
  • SPDiagnosticsDataType
  • SPDisabledSoftwareDataType
  • SPDiscBurningDataType
  • SPEthernetDataType
  • SPExtensionsDataType
  • SPFibreChannelDataType
  • SPFireWireDataType
  • SPFirewallDataType
  • SPFontsDataType
  • SPFrameworksDataType
  • SPDisplaysDataType
  • SPHardwareDataType
  • SPHardwareRAIDDataType
  • SPInstallHistoryDataType
  • SPNetworkLocationDataType
  • SPLogsDataType
  • SPManagedClientDataType
  • SPMemoryDataType
  • SPNVMeDataType
  • SPNetworkDataType
  • SPPCIDataType
  • SPParallelSCSIDataType
  • SPPowerDataType
  • SPPrefPaneDataType
  • SPPrintersSoftwareDataType
  • SPPrintersDataType
  • SPConfigurationProfileDataType
  • SPSASDataType
  • SPSerialATADataType
  • SPSPIDataType
  • SPSoftwareDataType
  • SPStartupItemDataType
  • SPStorageDataType
  • SPSyncServicesDataType
  • SPThunderboltDataType
  • SPUSBDataType
  • SPNetworkVolumeDataType
  • SPWWANDataType
  • SPAirPortDataType

接下来, 根据数据类型生成一个文本文件的报告 — 例如, 硬件数据类型 — 仅在命令后边添加数据类型:

$ system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro12,1
      Processor Name: Intel Core i5
      Processor Speed: 2.7 GHz
      Number of Processors: 1
      Total Number of Cores: 2
      L2 Cache (per Core): 256 KB
      L3 Cache: 3 MB
      Memory: 16 GB
      Boot ROM Version: MBP121.0167.B07
      SMC Version (system): 2.28f7
      Serial Number (system): XXXXXXXXXXXX
      Hardware UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

也可以使用复合数据类型 生成你想要的报告。

$ system_profiler SPEthernetDataType SPPrintersDataType
Ethernet Cards:

    USB Ethernet Adapter - AX88772A:

      Type: USB
      BSD name: en5
      Kext name: AppleUSBEthernet.kext
      Location: /System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleUSBEthernet.kext
      Version: 2.4.13
      MAC Address: 00:0e:c6:f9:23:0b
      Product ID: 30506
      Vendor ID: 2965

Printers:

    Brother HL-2230 series-05d7a2:

      Status: Idle
      Print Server: Local
      Driver Version: 4.5.0
      Default: No
      System Printer Sharing: No
      Shared: No
      URI: dnssd://Brother%20HL-2230%20series-05d7a2._printer._tcp.local./F904440001
      PPD: Brother HL-2230 series CUPS
      PPD File Version: 4.5.0
      PostScript Version: (3010.106) 3
      CUPS Version: 2.0.0 (cups-408.2)
      Scanning support: No
      Printer Commands: ReportLevels PrintSelfTestPage PJLBidirectional PJLWrite PJLRead
      CUPS filters:
        rastertobrother2130:
          Path: /Library/Printers/Brother/Filter/rastertobrother2130.bundle/Contents/MacOS/rastertobrother2130
          Permissions: rwxr-xr-x
          Version: 4.1.0
        commandtobrother:
          Path: /Library/Printers/Brother/Filter/commandtobrother.bundle/Contents/MacOS/commandtobrother
          Permissions: rwxr-xr-x
          Version: 4.4.0
      Fax support: No
      Printer utility: /Library/Printers/Brother/Utilities/BrStatusMonitor.app
      Printer utility version: 3.9.1
      PDEs:
        BRMLQuality.bundle:
          Sandbox compliant: Yes

输出 XML 格式的报告

可以 传入参数 -xml 来生成 XML 格式的报告。 xml标签可以结合之前的命令定制包含所需信息的报告。

$ system_profiler -xml SPEthernetDataType SPFirewallDataType > ~/Documents/reports/system_profile-EthernetFirewall.xml

 

system profiler with the xml flag enabled
system_profiler 命令输出的 XML 格式的报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值