命令列獲取 mac os x 系統資訊
阿新 • • 發佈:2019-01-26
如果你在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 種 不同級別的報告模式
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 格式的報告