lshw命令详解
lshw命令详解
1、lshw命令介绍
lshw(ls hardware)是一个提取机器硬件配置详细信息的工具,它能为我们提供内存配置、固件版本、主板配置信息、cpu版本和速度、cache信息、总线速度等。并且能将结果输出成HTML、XML、json等格式。
lshw 不仅是一个可以查看硬件信息的工具,它还可以用来做一些硬件的 benchmark,用于评估计算机硬件的性能特征。lshw 工具其实就是读取 /proc 里面的一些文件来显示相关的信息,比如:
/proc/cpuinfo # 显示CPU信息
/proc/bus/pci # 显示pci信息
/proc/scsi # 显示scsi信息
/proc/net/dev # 显示网络设备信息
/proc/kcore # 从内存映像读取相关信息
/proc/ide # 显示IDE设备信息
/proc/devices
/proc/mounts
/proc/fstab
shw 工具适用于所有 Linux 发行版,包括 Redhat、Centos、Ubuntu、Debian、Arch Linux 等。
-
如果系统中没有lshw命令,可通过下面的方式进行安装
-
基于debian的loongnix操作系统安装:apt install lshw -y
-
基于centos的loongnix-server操作系统安装:yum install lshw -y
2、语法格式
- lshw [-format][-options...]
- 注意:需要以root身份执行lshw命令
3、选项及参数
3.1. format
| 参数 | 说明 |
|---|---|
| -html | 将结果以HTML格式打印 |
| -xml | 将结果以xml格式打印 |
| -json | 将结果以json格式打印 |
| -short | 输出硬件路径 |
| -businfo | 输出总线信息。SCSI、USB、IDE、PCI地址等 |
3.2. options
| 参数 | 说明 |
|---|---|
| -dump filename | 将收集到的信息输出到一个SQLite数据库中 |
| -class CLASS | 仅显示指定类型的硬件,可使用lshw -sort或者lshw -businfo查找CLASS,常见的CLASS:system、bus、memory、processor、bridge、display、network、input、multimedia、communication、generic、storage、disk、volume<br/ |
| -C CLASS | 等同于’-class CLASS’ |
| -c CLASS | 等同于‘-c CLASS’ |
| -enable TEST | 启用测试 |
| -dump filename | 测试项包含:dmi、device-tree、spd、memory、cpuinfo、cpuid、pci、isapnp、pcmcia、ide、usb、scsi、network |
| -disable TEST | 禁用测试 |
| -quiet | 不显示状态 |
| -sanitize | 移除IP地址、序列号等敏感信息 |
| -numeric | 显示PCI和USB设备的数字ID |
| -notime | 从输出中排除经常改变的属性(如时间戳) |
4、参考实例
4.1 实例一:将硬件配置信息以html格式输出
[root@localhost ~]# lshw -html
……
<div class="indented">
<div class="indented">
<table width="100%" class="node" summary="attributes of input:4">
<thead><tr><td class="first">id:</td><td class="second"><div class="id">input:4</div></td></tr></thead>
<tbody>
<tr><td class="first">product: </td><td class="second">spice vdagent tablet</td></tr>
<tr><td class="first">physical id: </td><td class="second"><div class="id">5</div></td></tr>
<tr><td class="first">logical name: </td><td class="second"><div class="id">input8</div></td></tr>
<tr><td class="first">logical name: </td><td class="second"><div class="id">/dev/input/event5</div></td></tr>
<tr><td class="first">logical name: </td><td class="second"><div class="id">/dev/input/js0</div></td></tr>
<tr><td class="first">logical name: </td><td class="second"><div class="id">/dev/input/mouse2</div></td></tr>
</tbody> </table></div>
</div>
……
4.2 实例二:显示硬件设备列表,输出总线信息
[root@localhost ~]# lshw -businfo
Bus info Device Class Description
========================================================
system Standard PC (Q35 + ICH9, 2009)
bus Motherboard
memory 96KiB BIOS
cpu@0 processor Intel Xeon Processor (Cooperlake)
cpu@1 processor Intel Xeon Processor (Cooperlake)
memory 1536MiB System Memory
memory DIMM RAM [empty]
pci@0000:00:00.0 bridge 82G33/G31/P35/P31 Express DRAM Controller
pci@0000:00:01.0 /dev/fb0 display QXL paravirtual graphic card
pci@0000:00:02.0 bridge QEMU PCIe Root port
pci@0000:01:00.0 network Virtio network device
virtio@0 enp1s0 network Ethernet interface
pci@0000:00:02.1 bridge QEMU PCIe Root port
pci@0000:02:00.0 bus QEMU XHCI Host Controller
usb@1 usb1 bus xHCI Host Controller
4.3 实例三:显示内存相关的硬件信息
[root@localhost ~]# lshw -c memory
*-firmware
description: BIOS
vendor: SeaBIOS
physical id: 0
version: 1.14.0-2
date: 04/01/2014
size: 96KiB
*-memory
description: System Memory
physical id: 1000
size: 1536MiB
capacity: 1536MiB
capabilities: ecc
configuration: errordetection=multi-bit-ecc
*-bank
description: DIMM RAM [empty]
vendor: QEMU
physical id: 0
slot: DIMM 0
浙公网安备 33010602011771号