检查和收集 Linux 硬件信息的 7 个命令

系统 Linux
在Linux系统中,有许多命令可用于查询主机的硬件信息。一些命令只针对特定的硬件组件,比如CPU、内存,一些命令可以查询多个硬件信息。这篇文章只是简单的让每个人了解查询硬件信息的基本命令使用,包括lscpu、hwinfo、lshw、lspci、lsblk、lsusb等等。

 

在Linux系统中,有许多命令可用于查询主机的硬件信息。一些命令只针对特定的硬件组件,比如CPU、内存,一些命令可以查询多个硬件信息。

这篇文章只是简单的让每个人了解查询硬件信息的基本命令使用,包括lscpu、hwinfo、lshw、lspci、lsblk、lsusb等等。

1. lscpu用于查询CPU信息

  1. [root@devops ~]# lscpu 
  2. Architecture:          x86_64 
  3. CPU op-mode(s):        32-bit, 64-bit 
  4. Byte Order:            Little Endian 
  5. CPU(s):                1 
  6. On-line CPU(s) list:   0 
  7. Thread(s) per core:    1 
  8. Core(s) per socket:    1 
  9. CPU socket(s):         1 
  10. NUMA node(s):          1 
  11. Vendor ID:             GenuineIntel 
  12. CPU family:            6 
  13. Model:                 45 
  14. Stepping:              7 
  15. CPU MHz:               2194.842 
  16. BogoMIPS:              4389.68 
  17. Hypervisor vendor:     Xen 
  18. Virtualization type:   full 
  19. L1d cache:             32K 
  20. L1i cache:             32K 
  21. L2 cache:              256K 
  22. L3 cache:              15360K 
  23. NUMA node0 CPU(s):     0 

2. lshw显示硬件信息表

这个命令应用普遍,它可通过个人需求而列出多种不同的硬件参数:CPU、内存、硬盘、USB控制器、lshw卡片等等,本质上就是从/proc目录不同文件中中提取对应的硬件信息。

按照下面的步骤去安装lshw工具,然后就可以使用了。

  1. wget http://ezix.org/software/files/lshw-B.02.14.tar.gz 
  2. tar -zxvf lshw-B.02.14.tar.gz 
  3. cd lshw-B.02.14 
  4. make && make install 
  5. 示例: 
  6. [root@devops lshw-B.02.14]# lshw -short 
  7. H/W path          Device       Class      Description 
  8. ===================================================== 
  9. system     HVM domU 
  10. /0                             bus        Motherboard 
  11. /0/0                           memory     96KiB BIOS 
  12. /0/1                           processor  Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz 
  13. /0/2                           memory     System Memory 
  14. /0/2/0                         memory     512MiB DIMM RAM 
  15. /0/2/1                         memory     512MiB DIMM RAM 
  16. /0/3                           memory     96KiB BIOS 
  17. /0/4                           processor  CPU 
  18. /0/5                           memory     System Memory 
  19. /0/6                           memory 
  20. /0/7                           memory 
  21. /0/100                         bridge     440FX - 82441FX PMC [Natoma] 
  22. /0/100/1                       bridge     82371SB PIIX3 ISA [Natoma/Triton II] 
  23. /0/100/1.1        scsi1        storage    82371SB PIIX3 IDE [Natoma/Triton II] 
  24. /0/100/1.1/0.0.0  /dev/cdrom1  disk       SCSI CD-ROM 
  25. /0/100/1.2                     bus        82371SB PIIX3 USB [Natoma/Triton II] 
  26. /0/100/1.2/1      usb1         bus        UHCI Host Controller 
  27. /0/100/1.2/1/2                 input      QEMU USB Tablet 
  28. /0/100/1.3                     bridge     82371AB/EB/MB PIIX4 ACPI 
  29. /0/100/2                       display    GD 5446 
  30. /0/100/3                       generic    Xen Platform Device 
  31. /1                eth0         network    Ethernet interface 
  32. /2                eth1         network    Ethernet interface 
  33. [root@devops lshw-B.02.14]# 

3. hwinfo-硬件信息

hwinfo类似于lshw,也能查询硬件信息,且应用广泛。它也能输出多个硬件部分的详细或者简要信息,但是不同的是有时hwinfo比lshw的信息更详细。

默认情况下,Linux系统没有安装hwinfo工具,所以你需要按照以下步骤自己安装:

CentOS 6

  1. #rpm -Uvh http://mirror.symnds.com/distributions/gf/el/6/gf/x86_64/gf-release-6-6.gf.el6.noarch.rpm 
  2. #yum list hwinfo 
  3. #yum install hwinfo 

CentOS 5

  1. #rpm -Uvh http://mirror.symnds.com/distributions/gf/el/5/gf/x86_64/gf-release-5-6.gf.el5.noarch.rpm 
  2. #yum list hwinfo 
  3. #yum install hwinfo 
  1. [root@devops tmp]# rpm -Uvh http://mirror.symnds.com/distributions/gf/el/6/gf/x86_64/gf-release-6-6.gf.el6.noarch.rpm 
  2. Retrieving http://mirror.symnds.com/distributions/gf/el/6/gf/x86_64/gf-release-6-6.gf.el6.noarch.rpm 
  3. warning: /var/tmp/rpm-tmp.m2mMAO: Header V4 RSA/SHA1 Signature, key ID 13a4d2a9: NOKEY 
  4. Preparing...                ########################################### [100%] 
  5.    1:gf-release             ########################################### [100%] 
  6. [root@devops tmp]# yum list hwinfo 
  7. Loaded plugins: fastestmirror 
  8. Loading mirror speeds from cached hostfile 
  9.  * base: mirrors.aliyun.com 
  10.  * extras: mirrors.aliyun.com 
  11.  * updates: mirrors.aliyun.com 
  12. gf                                                                                                     
  13.  00:00      
  14. gf/primary_db                                                                                      
  15.  00:00      
  16. Available Packages 
  17. hwinfo.x86_64 
  18. [root@devops tmp]# yum list hwinfo 
  19. Loaded plugins: fastestmirror 
  20. Loading mirror speeds from cached hostfile 
  21.  * base: mirrors.aliyun.com 
  22.  * extras: mirrors.aliyun.com 
  23.  * updates: mirrors.aliyun.com 
  24. gf                                                                                                    
  25.  00:00      
  26. gf/primary_db                                                                                           
  27.  00:00      
  28. Available Packages 
  29. hwinfo.x86_64               20.2-1.gf.el6 
  1. [root@devops tmp]# yum install hwinfo 
  2. Loaded plugins: fastestmirror 
  3. Loading mirror speeds from cached hostfile 
  4.  * base: mirrors.aliyun.com 
  5.  * extras: mirrors.aliyun.com 
  6.  * updates: mirrors.aliyun.com 
  7. Setting up Install Process 
  8. Resolving Dependencies 
  9. --> Running transaction check 
  10. ---> Package hwinfo.x86_64 0:20.2-1.gf.el6 will be installed 
  11. ..... 

示例:

  1. [root@devops tmp]# hwinfo -short 
  2. oops: don't know what to do with "short" 
  3. [root@devops tmp]# hwinfo --short 
  4. cpu:                                                             
  5.                        Intel(R) Xeon(R) CPU E5-2430 0 @ 2.20GHz, 2194 MHz 
  6. keyboard: 
  7.   /dev/input/event3    AT Translated Set 2 keyboard 
  8.   /dev/ttyS0           serial console 
  9. mouse: 
  10.   /dev/input/mice      Adomax QEMU USB Tablet 
  11.   /dev/input/mice      Macintosh mouse button emulation 
  12.   /dev/input/mice      ImExPS/2 Generic Explorer Mouse 
  13. graphics card: 
  14.                        Cirrus Logic GD 5446 
  15. storage: 
  16.                        Intel 82371SB PIIX3 IDE [Natoma/Triton II] 
  17.                        Xen Virtual Storage 0 
  18.                        Xen Virtual Storage 1 
  19.                        Xen Virtual Storage 2 
  20. network: 
  21.   eth0                 Xen Virtual Ethernet Card 0 
  22.   eth1                 Xen Virtual Ethernet Card 1 
  23. network interface: 
  24.   lo                   Loopback network interface 
  25.   eth0                 Ethernet network interface 
  26.   eth1                 Ethernet network interface 
  27. disk: 
  28.   /dev/xvda            Disk 
  29.   /dev/xvdb            Disk 
  30. partition: 
  31.   /dev/xvda1           Partition 
  32.   /dev/xvdb1           Partition 
  33. cdrom: 
  34.   /dev/sr0             QEMU DVD-ROM 
  35. usb controller: 
  36.                        Qumranet Qemu virtual machine 
  37. bios: 
  38.                        BIOS 
  39. bridge: 
  40.                        Qumranet Qemu virtual machine 
  41.                        Qumranet Qemu virtual machine 
  42.                        Qumranet Qemu virtual machine 
  43. hub: 
  44.                        Linux 2.6.32-279.el6.x86_64 uhci_hcd UHCI Host Controller 
  45. memory: 
  46.                        Main Memory 
  47. unknown: 
  48.                        FPU 
  49.                        DMA controller 
  50.                        PIC 
  51.                        Timer 
  52.                        Keyboard controller 
  53.                        XenSource Xen Platform Device 
  54. [root@devops tmp]# 

4. lspci

lsppci命令可列出PCI总线的信息以及连接到PCI总线上的设备信息,比如VGA适配器、SATA控制器、其他模块等等。lspci工具是pciutils包的一部分,所以在安装lspci之前,你需要安装pciutils包。

安装pciutils包使用下面的命令:

  1. #yum install pciutils 
  1. [root@devops tmp]# yum install pciutils 
  2. Loaded plugins: fastestmirror 
  3. Loading mirror speeds from cached hostfile 
  4.  * base: mirrors.aliyun.com 
  5.  * extras: mirrors.aliyun.com 
  6.  * updates: mirrors.aliyun.com 
  7. Setting up Install Process 
  8. Resolving Dependencies 
  9. --> Running transaction check 
  10. ---> Package pciutils.x86_64 0:3.1.10-2.el6 will be installed 
  11. --> Processing Dependency: pciutils-libs = 3.1.10-2.el6 for package: pciutils-3.1.10-2.el6.x86_64 
  12. --> Running transaction check 
  13. ---> Package pciutils-libs.x86_64 0:3.1.4-11.el6 will be updated 
  14. ---> Package pciutils-libs.x86_64 0:3.1.10-2.el6 will be an update 
  15. --> Finished Dependency Resolution 
  16. Dependencies Resolved 
  17. Installing: 
  18.  pciutils                         x86_64                    3.1.10-2.el6                
  19.       85 k 
  20. Updating for dependencies: 
  21.  pciutils-libs                    x86_64                    3.1.10-2.el6                  
  22.       34 k 
  23. .....   
  24. Dependency Updated: 
  25.   pciutils-libs.x86_64 0:3.1.10-2.el6                                                                             
  26. Complete! 

示例:

  1. [root@devops tmp]# lspci  
  2. 00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 
  3. 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 
  4. 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 
  5. 00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) 
  6. 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 01) 
  7. 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 
  8. 00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01) 
  9. [root@devops tmp]# 

5. lsusb-列出USB总线信息

这个命令可列出USB控制器的设备信息。

lsusb工具是usbutils包的一部分,所以你需要按照如下命令安装:

  1. #yum install usbutils 
  1. [root@devops tmp]# yum install usbutils 
  2. Loaded plugins: fastestmirror 
  3. Loading mirror speeds from cached hostfile 
  4.  * base: mirrors.aliyun.com 
  5.  * extras: mirrors.aliyun.com 
  6.  * updates: mirrors.aliyun.com 
  7. Setting up Install Process 
  8. Resolving Dependencies 
  9. --> Running transaction check 
  10. ---> Package usbutils.x86_64 0:003-4.el6 will be installed 
  11. --> Processing Dependency: libusb-1.0.so.0()(64bit) for package: usbutils-003-4.el6.x86_64 
  12. --> Running transaction check 
  13. ---> Package libusb1.x86_64 0:1.0.9-0.6.rc1.el6 will be installed 
  14. --> Finished Dependency Resolution 
  15. Dependencies Resolved 
  16. ============================================ 
  17.  Package                     Arch                      Version                               
  18.       Size 
  19. ======================================================= 
  20.  
  21. Installing: 
  22.  usbutils                    x86_64                    003-4.el6                                   
  23.       71 k 
  24. Installing for dependencies: 
  25.  libusb1                     x86_64                    1.0.9-0.6.rc1.el6                       
  26.       80 k 
  27. Transaction Summary 
  28. ================================================================ 
  29. Install       2 Package(s) 
  30. Total download size: 152 k 
  31. Installed size: 377 k 
  32. Is this ok [y/N]: y 
  33. Downloading Packages: 
  34. (1/2): libusb1-1.0.9-0.6.rc1.el6.x86_64.rpm                                                      
  35.  00:00      
  36. (2/2): usbutils-003-4.el6.x86_64.rpm                                                
  37.  00:00      
  38. -------------------------------------------------------- 
  39. Total                                                                                      
  40.  00:00      
  41. Running rpm_check_debug 
  42. Running Transaction Test 
  43. Transaction Test Succeeded 
  44. Running Transaction 
  45.   Installing : libusb1-1.0.9-0.6.rc1.el6.x86_64                                                                   
  46.        1/2  
  47.   Installing : usbutils-003-4.el6.x86_64                                                                          
  48.        2/2  
  49.   Verifying  : usbutils-003-4.el6.x86_64                                                                          
  50.        1/2  
  51.   Verifying  : libusb1-1.0.9-0.6.rc1.el6.x86_64                                                                   
  52.        2/2  
  53. Installed: 
  54.   usbutils.x86_64 0:003-4.el6                                                                                     
  55. Dependency Installed: 
  56.   libusb1.x86_64 0:1.0.9-0.6.rc1.el6                                                                              
  57. Complete! 

示例:

  1. [root@devops tmp]# lsusb 
  2. Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 
  3. Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd  
  4. [root@devops tmp]# 

6. lsblk-列出块设备的信息

  1. [root@devops tmp]# lsblk 
  2. NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT 
  3. xvda    202:0    0    20G  0 disk  
  4. └─xvda1 202:1    0    20G  0 part / 
  5. xvdb    202:16   0    10G  0 disk  
  6. └─xvdb1 202:17   0    10G  0 part /alidata 
  7. sr0      11:0    1   362K  0 rom 

7. lsscsi-列出SCSI的设备信息

列出SCSI/SDAT设备的信息,比如硬盘驱动器、光盘驱动器。

  1. [root@devops tmp]# lsscsi 
  2. [1:0:0:0]    cd/dvd  QEMU     QEMU DVD-ROM     0.10  /dev/sr0  
  3. [root@devops tmp]# 

完毕!Enjoy this!

原文链接:7 Linux commands to check/gather hardware information in linux system

 

责任编辑:黄丹 来源: oschina
相关推荐

2015-12-03 09:46:50

收集硬件Linux命令

2018-01-08 15:50:21

Linux命令系统和硬件

2015-09-23 09:22:01

系统硬件命令

2014-08-13 10:15:00

Linuxdmesg命令

2014-05-04 10:34:32

Linux硬件信息Linux命令

2021-04-09 11:42:16

Linux 系统硬件操作系统

2010-03-02 14:01:58

Linux硬件信息命令

2011-07-19 09:25:52

2018-08-09 08:00:00

Linux命令内存用量

2015-05-25 19:37:17

InxiLinux

2010-05-27 15:41:28

Linux查看用户

2009-12-11 15:47:54

Linux硬件信息

2009-09-25 10:48:07

Linux硬件信息操作系统

2012-05-11 10:18:52

Linuxhwclock

2009-08-03 14:31:16

Linux命令linux操作系统

2015-07-29 10:34:50

Linux系统命令行工具

2015-07-30 11:24:47

Linux 系统命令行工具

2015-07-30 11:04:08

Linux命令行工具

2011-04-02 11:20:01

2009-12-16 14:44:11

Linux硬件查询命令
点赞
收藏

51CTO技术栈公众号