当前位置: 代码网 > 服务器>服务器>Linux > Linux查看硬件信息常用命令有哪些

Linux查看硬件信息常用命令有哪些

2026年09月01日 Linux 我要评论
一、 块设备查看【lsblk】[root@localhost ~]# lsblkname maj:min rm size ro type mountpointsda

一、 块设备查看【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 ~]# 

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com