Linux查看硬件信息常用命令有哪些
更新时间:2026年09月01日 10:01:03 作者:ldwtxwh
还在为Linux下查看硬件信息发愁吗?本文汇总了lsblk、lshw、lspci、lsusb、dmidecode等常用命令,手把手教你查看块设备、PCI设备、USB设备和硬件组件信息,轻松掌握系统硬件配置
一、 块设备查看【lsblk】
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─centos-root 253:0 0 35.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sr0 11:0 1 918M 0 rom [root@localhost ~]#
二、查看硬件信息【lshw】
[root@localhost ~]# lshw -h
Hardware Lister (lshw) - B.02.18
usage: lshw [-format] [-options ...]
lshw -version
-version print program version (B.02.18)
format can be
-html output hardware tree as HTML
-xml output hardware tree as XML
-json output hardware tree as a JSON object
-short output hardware paths
-businfo output bus information
options can be
-dump filename displays output and dump collected information into a file (SQLite database)
-class CLASS only show a certain class of hardware
-C CLASS same as '-class CLASS'
-c CLASS same as '-class CLASS'
-disable TEST disable a test (like pci, isapnp, cpuid, etc. )
-enable TEST enable a test (like pci, isapnp, cpuid, etc. )
-quiet don't display status
-sanitize sanitize output (remove sensitive information like serial numbers, etc.)
-numeric output numeric IDs (for PCI, USB, etc.)
-notime exclude volatile attributes (timestamps) from output
[root@localhost ~]#
该命令输出的信息较多,该处不展示命令输出,为了方便查看也可以通过格式化输出,支持html,xml,json等格式的输出。
三、列出所有PCI设备【lspci】
[root@localhost ~]# lspci -bash: lspci: 未找到命令
如果提示没有该命令,需要安装该工具包,如下:
[root@localhost ~]# yum install pciutils 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 pciutils.x86_64.0.3.5.1-3.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 =============================================================================================================================================================================================================================== Package 架构 版本 源 大小 =============================================================================================================================================================================================================================== 正在安装: pciutils x86_64 3.5.1-3.el7 base 93 k 事务概要 =============================================================================================================================================================================================================================== 安装 1 软件包 总下载量:93 k 安装大小:196 k Is this ok [y/d/N]:
安装完后执行命令如下:
[root@localhost ~]# lspci 00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01) 00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01) 00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08) 00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01) 00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08) 00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10) 00:0f.0 VGA compatible controller: VMware SVGA II Adapter 00:10.0 SCSI storage controller: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01) 00:11.0 PCI bridge: VMware PCI bridge (rev 02) 00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01) 00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01) 00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01) 00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01) 00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01) 02:00.0 USB controller: VMware USB1.1 UHCI Controller 02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) 02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02) 02:03.0 USB controller: VMware USB2 EHCI Controller [root@localhost ~]#
四、列出所有USB设备【lsusb】
lsusb的工具包安装命令如下:
yum -y install usbutils
执行命令如下:
[root@localhost ~]# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub [root@localhost ~]#
五、查看硬件系统组件【dmidecode】
[root@localhost ~]# dmidecode -h
Usage: dmidecode [OPTIONS]
Options are:
-d, --dev-mem FILE Read memory from device FILE (default: /dev/mem)
-h, --help Display this help text and exit
-q, --quiet Less verbose output
-s, --string KEYWORD Only display the value of the given DMI string
-t, --type TYPE Only display the entries of given type
-H, --handle HANDLE Only display the entry of given handle
-u, --dump Do not decode the entries
--dump-bin FILE Dump the DMI data to a binary file
--from-dump FILE Read the DMI data from a binary file
--no-sysfs Do not attempt to read DMI data from sysfs files
--oem-string N Only display the value of the given OEM string
-V, --version Display the version and exit
硬件组件信息较多,可以执行输出到文件查看
六、查看或管理磁盘分区表【fdisk】
[root@localhost ~]# fdisk -l 磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x00095121 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 83886079 40893440 8e Linux LVM 磁盘 /dev/mapper/centos-root:37.7 GB, 37706792960 字节,73646080 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 [root@localhost ~]#
该命令详解请移步我的上一篇博文
七、显示或设置SATA/IDE设备参数【hdparm】
[root@localhost ~]# hdparm hdparm - get/set hard disk parameters - version v9.43, by Mark Lord. Usage: hdparm [options] [device ...] Options: -a Get/set fs readahead -A Get/set the drive look-ahead flag (0/1) -b Get/set bus state (0 == off, 1 == on, 2 == tristate) -B Set Advanced Power Management setting (1-255) -c Get/set IDE 32-bit IO setting -C Check drive power mode status -d Get/set using_dma flag -D Enable/disable drive defect management -E Set cd/dvd drive speed -f Flush buffer cache for device on exit -F Flush drive write cache -g Display drive geometry -h Display terse usage information -H Read temperature from drive (Hitachi only) -i Display drive identification -I Detailed/current information directly from drive -J Get/set Western DIgital "Idle3" timeout for a WDC "Green" drive (DANGEROUS) -k Get/set keep_settings_over_reset flag (0/1) -K Set drive keep_features_over_reset flag (0/1) -L Set drive doorlock (0/1) (removable harddisks only) -m Get/set multiple sector count -M Get/set acoustic management (0-254, 128: quiet, 254: fast) -n Get/set ignore-write-errors flag (0/1) -N Get/set max visible number of sectors (HPA) (VERY DANGEROUS) -p Set PIO mode on IDE interface chipset (0,1,2,3,4,...) -P Set drive prefetch count -q Change next setting quietly -Q Get/set DMA queue_depth (if supported) -r Get/set device readonly flag (DANGEROUS to set) -R Get/set device write-read-verify flag -s Set power-up in standby flag (0/1) (DANGEROUS) -S Set standby (spindown) timeout -t Perform device read timings -T Perform cache read timings -u Get/set unmaskirq flag (0/1) -U Obsolete -v Use defaults; same as -acdgkmur for IDE drives -V Display program version and exit immediately -w Perform device reset (DANGEROUS) -W Get/set drive write-caching flag (0/1) -x Obsolete -X Set IDE xfer mode (DANGEROUS) -y Put drive in standby mode -Y Put drive to sleep -z Re-read partition table -Z Disable Seagate auto-powersaving mode --dco-freeze Freeze/lock current device configuration until next power cycle --dco-identify Read/dump device configuration identify data --dco-restore Reset device configuration back to factory defaults --direct Use O_DIRECT to bypass page cache for timings --drq-hsm-error Crash system with a "stuck DRQ" error (VERY DANGEROUS) --fallocate Create a file without writing data to disk --fibmap Show device extents (and fragmentation) for a file --fwdownload Download firmware file to drive (EXTREMELY DANGEROUS) --fwdownload-mode3 Download firmware using min-size segments (EXTREMELY DANGEROUS) --fwdownload-mode3-max Download firmware using max-size segments (EXTREMELY DANGEROUS) --fwdownload-mode7 Download firmware using a single segment (EXTREMELY DANGEROUS) --idle-immediate Idle drive immediately --idle-unload Idle immediately and unload heads --Istdin Read identify data from stdin as ASCII hex --Istdout Write identify data to stdout as ASCII hex --make-bad-sector Deliberately corrupt a sector directly on the media (VERY DANGEROUS) --offset use with -t, to begin timings at given offset (in GiB) from start of drive --prefer-ata12 Use 12-byte (instead of 16-byte) SAT commands when possible --read-sector Read and dump (in hex) a sector directly from the media --repair-sector Alias for the --write-sector option (VERY DANGEROUS) --security-help Display help for ATA security commands --trim-sector-ranges Tell SSD firmware to discard unneeded data sectors: lba:count .. --trim-sector-ranges-stdin Same as above, but reads lba:count pairs from stdin --verbose Display extra diagnostics from some commands --write-sector Repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS) [root@localhost ~]#
八、用于I2C通信的工具【i2c-tools】
安装命令:
[root@localhost ~]# yum install i2c-tools 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 i2c-tools.x86_64.0.3.1.0-13.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================================================================================================================================= Package 架构 版本 源 大小 ============================================================================================================================================================================================================================= 正在安装: i2c-tools x86_64 3.1.0-13.el7 base 71 k 事务概要 ============================================================================================================================================================================================================================= 安装 1 软件包
[root@localhost ~]# i2cget
Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
b (read byte data, default)
w (read word data)
c (write byte/read byte)
Append p for SMBus PEC
九、显示CPU架构信息【lscpu】
[root@localhost ~]# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 1 座: 4 NUMA 节点: 1 厂商 ID: GenuineIntel CPU 系列: 6 型号: 151 型号名称: 12th Gen Intel(R) Core(TM) i5-12500 步进: 5 CPU MHz: 2995.203 BogoMIPS: 5990.40 超管理器厂商: VMware 虚拟化类型: 完全 L1d 缓存: 48K L1i 缓存: 32K L2 缓存: 1280K L3 缓存: 18432K NUMA 节点0 CPU: 0-3 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd rsb_ctxsw ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 arat umip pku ospke gfni vaes vpclmulqdq movdiri movdir64b md_clear spec_ctrl intel_stibp flush_l1d arch_capabilities [root@localhost ~]#
十、查看内存使用情况【free】
[root@localhost ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 690M 2.6G 11M 436M 2.8G
Swap: 3.9G 0B 3.9G
[root@localhost ~]#
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。


最新评论