如果你在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 种 不同级别的报告模式: mini, basic 和 full。
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 命令输出的 XML 格式的报告