10 个用于收集硬件信息的 Linux 命令

开发
知道自己的Linux系统运行在什么样的硬件组件上总是好的,因为如果涉及到在系统上安装软件包和驱动程序的话,这将有助于你处理兼容性问题。

知道自己的Linux系统运行在什么样的硬件组件上总是好的,因为如果涉及到在系统上安装软件包和驱动程序的话,这将有助于你处理兼容性问题。

因此,下面我们将给出一些非常有用的命令,它们可以帮助你提取你的Linux系统和硬件组件的信息。

1.如何查看Linux系统的信息

如果只想知道系统名称,可以使用不带任何参数选项的uname命令,就可以输出系统信息,或使用uname -s命令输出系统的内核名称。

  1. tecmint@tecmint ~ $ uname 
  2. Linux 

要查看网络主机名,用“-n”参数选项的uname命令,如下所示。

 

  1. tecmint@tecmint ~ $ uname -n 
  2. tecmint.com 

要获取有关内核版本的信息,使用“-v”参数选项。

  1. tecmint@tecmint ~ $ uname -v 

#64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014

要得到有关你的内核的发行版信息,请使用“-r”参数选项。

 

  1. tecmint@tecmint ~ $ uname -r 
  2. 3.13.0-37-generic 

要输出你的机器的硬件名,使用“-m”参数选项:

  1. tecmint@tecmint ~ $ uname -m 
  2. x86_64 

所有这些信息可以通过运行“uname -a”命令,如下图所示一次性输出。

 

  1. tecmint@tecmint ~ $ uname -a 
  2. Linux tecmint.com 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 

2.如何查看Linux的系统硬件信息

你可以使用lshw工具来收集有关硬件部件,如CPU,硬盘,内存,USB控制器等的大量信息。

lshw是一个相对比较小巧的工具,当你提取信息的时候,只有为数不多的几个选项可供你使用。由lshw提供的信息收集形成了不同的/ proc文件。

注:请记住,lshw命令是由superuser (root)或sudo用户执行的。

参见:《Difference Between su and sudo User in Linux

要输出你的Linux系统的硬件信息,运行此命令。

 

  1. tecmint@tecmint ~ $ sudo lshw 
  2.  
  3. tecmint.com               
  4.     description: Notebook 
  5.     product: 20354 (LENOVO_MT_20354_BU_idea_FM_Lenovo Z50-70
  6.     vendor: LENOVO 
  7.     version: Lenovo Z50-70 
  8.     serial: 1037407803441 
  9.     width: 64 bits 
  10.     capabilities: smbios-2.7 dmi-2.7 vsyscall32 
  11.     configuration: administrator_password=disabled boot=normal chassis=notebook family=IDEAPAD frontpanel_password=disabled keyboard_password=disabled power-on_password=disabled sku=LENOVO_MT_20354_BU_idea_FM_Lenovo Z50-70 uuid=E4B1D229-D237-E411-9F6E-28D244EBBD98 
  12.   *-core 
  13.        description: Motherboard 
  14.        product: Lancer 5A5 
  15.        vendor: LENOVO 
  16.        physical id: 0 
  17.        version: 31900059WIN 
  18.        serial: YB06377069 
  19.        slot: Type2 - Board Chassis Location 
  20.      *-firmware 
  21.           description: BIOS 
  22.           vendor: LENOVO 
  23.           physical id: 0 
  24.           version: 9BCN26WW 
  25.           date: 07/31/2014 
  26.           size: 128KiB 
  27.           capacity: 4032KiB 
  28.           capabilities: pci upgrade shadowing cdboot bootselect edd int13floppynec int13floppytoshiba int13floppy360 int13floppy1200 int13floppy720 int13floppy2880 int9keyboard int10video acpi usb biosbootspecification uefi 
  29. ...... 

你可以通过使用-short选项来输出汇总的硬件信息。

 

  1. tecmint@tecmint ~ $ sudo lshw -short 
  2.  
  3. H/W path       Device      Class          Description 
  4. ===================================================== 
  5.                            system         20354 (LENOVO_MT_20354_BU_idea_FM_Lenovo Z50-70
  6. /0                         bus            Lancer 5A5 
  7. /0/0                       memory         128KiB BIOS 
  8. /0/4                       processor      Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz 
  9. /0/4/b                     memory         32KiB L1 cache 
  10. /0/4/c                     memory         256KiB L2 cache 
  11. /0/4/d                     memory         3MiB L3 cache 
  12. /0/a                       memory         32KiB L1 cache 
  13. /0/12                      memory         8GiB System Memory 
  14. /0/12/0                    memory         DIMM [empty] 
  15. /0/12/1                    memory         DIMM [empty] 
  16. /0/12/2                    memory         8GiB SODIMM DDR3 Synchronous 1600 MHz (0.6 ns) 
  17. /0/12/3                    memory         DIMM [empty] 
  18. /0/100                     bridge         Haswell-ULT DRAM Controller 
  19. /0/100/2                   display        Haswell-ULT Integrated Graphics Controller 
  20. /0/100/3                   multimedia     Haswell-ULT HD Audio Controller 
  21. ... 

如果你想生成输出为HTML文件,可以使用选项-html。

tecmint@tecmint ~ $ sudo lshw -html > lshw.html

3.如何查看Linux的CPU信息

要查看关于CPU的信息,就使用lscpu命令,因为它能从sysfs和/ proc / cpuinfo中显示CPU体系结构的信息,例如CPU数字,核心,CPU系列型号,CPU高速缓存,线程等。

 

  1. tecmint@tecmint ~ $ lscpu 
  2.  
  3. Architecture:          x86_64 
  4. CPU op-mode(s):        32-bit, 64-bit 
  5. Byte Order:            Little Endian 
  6. CPU(s):                4 
  7. On-line CPU(s) list:   0-3 
  8. Thread(s) per core:    2 
  9. Core(s) per socket:    2 
  10. Socket(s):             1 
  11. NUMA node(s):          1 
  12. Vendor ID:             GenuineIntel 
  13. CPU family:            6 
  14. Model:                 69 
  15. Stepping:              1 
  16. CPU MHz:               768.000 
  17. BogoMIPS:              4788.72 
  18. Virtualization:        VT-x 
  19. L1d cache:             32K 
  20. L1i cache:             32K 
  21. L2 cache:              256K 
  22. L3 cache:              3072K 
  23. NUMA node0 CPU(s):     0-3 

4.如何收集Linux块设备信息

块设备是诸如硬盘,闪存驱动器等的存储设备。lsblk命令可用于报告有关块设备的信息,如下所示。

 

  1. tecmint@tecmint ~ $ lsblk 
  2.  
  3. NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT 
  4. sda       8:0    0 931.5G  0 disk 
  5. ├─sda1    8:1    0  1000M  0 part 
  6. ├─sda2    8:2    0   260M  0 part /boot/efi 
  7. ├─sda3    8:3    0  1000M  0 part 
  8. ├─sda4    8:4    0   128M  0 part 
  9. ├─sda5    8:5    0 557.1G  0 part 
  10. ├─sda6    8:6    0    25G  0 part 
  11. ├─sda7    8:7    0  14.7G  0 part 
  12. ├─sda8    8:8    0     1M  0 part 
  13. ├─sda9    8:9    0 324.5G  0 part / 
  14. └─sda10   8:10   0   7.9G  0 part [SWAP] 
  15. sr0      11:0    1  1024M  0 rom 

如果你想查看系统上所有的块设备,那么就加一个-a选项。

 

  1. tecmint@tecmint ~ $ lsblk -a 
  2.  
  3. NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT 
  4. sda       8:0    0 931.5G  0 disk 
  5. ├─sda1    8:1    0  1000M  0 part 
  6. ├─sda2    8:2    0   260M  0 part /boot/efi 
  7. ├─sda3    8:3    0  1000M  0 part 
  8. ├─sda4    8:4    0   128M  0 part 
  9. ├─sda5    8:5    0 557.1G  0 part 
  10. ├─sda6    8:6    0    25G  0 part 
  11. ├─sda7    8:7    0  14.7G  0 part 
  12. ├─sda8    8:8    0     1M  0 part 
  13. ├─sda9    8:9    0 324.5G  0 part / 
  14. └─sda10   8:10   0   7.9G  0 part [SWAP] 
  15. sdb       8:16   1         0 disk 
  16. sr0      11:0    1  1024M  0 rom  
  17. ram0      1:0    0    64M  0 disk 
  18. ram1      1:1    0    64M  0 disk 
  19. ram2      1:2    0    64M  0 disk 
  20. ram3      1:3    0    64M  0 disk 
  21. ram4      1:4    0    64M  0 disk 
  22. ram5      1:5    0    64M  0 disk 
  23. ram6      1:6    0    64M  0 disk 
  24. ram7      1:7    0    64M  0 disk 
  25. ram8      1:8    0    64M  0 disk 
  26. ram9      1:9    0    64M  0 disk 
  27. loop0     7:0    0         0 loop 
  28. loop1     7:1    0         0 loop 
  29. loop2     7:2    0         0 loop 
  30. loop3     7:3    0         0 loop 
  31. loop4     7:4    0         0 loop 
  32. loop5     7:5    0         0 loop 
  33. loop6     7:6    0         0 loop 
  34. loop7     7:7    0         0 loop 
  35. ram10     1:10   0    64M  0 disk 
  36. ram11     1:11   0    64M  0 disk 
  37. ram12     1:12   0    64M  0 disk 
  38. ram13     1:13   0    64M  0 disk 
  39. ram14     1:14   0    64M  0 disk 
  40. ram15     1:15   0    64M  0 disk 

5.如何输出USB控制器的信息

lsusb命令可用于报告关于USB控制器和所有连接到它们的设备的信息。

 

  1. tecmint@tecmint ~ $ lsusb 
  2.  
  3. Bus 001 Device 002: ID 8087:8000 Intel Corp. 
  4. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
  5. Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
  6. Bus 002 Device 005: ID 0bda:b728 Realtek Semiconductor Corp. 
  7. Bus 002 Device 004: ID 5986:0249 Acer, Inc 
  8. Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller 
  9. Bus 002 Device 002: ID 045e:00cb Microsoft Corp. Basic Optical Mouse v2.0 
  10. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

你可以使用-v选项生成有关于每个USB设备的详细信息。

tecmint@tecmint ~ $ lsusb -v

6.如何输出PCI设备信息

PCI设备可能包括USB接口,显卡,网卡等。lspci工具能用来生成系统上所有PCI控制器以及连接到它们的设备的信息。

要输出有关PCI设备的信息,可运行以下命令。

 

  1. tecmint@tecmint ~ $ lspci 
  2.  
  3. 00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b) 
  4. 00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b) 
  5. 00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 0b) 
  6. 00:14.0 USB controller: Intel Corporation Lynx Point-LP USB xHCI HC (rev 04
  7. 00:16.0 Communication controller: Intel Corporation Lynx Point-LP HECI #0 (rev 04
  8. 00:1b.0 Audio device: Intel Corporation Lynx Point-LP HD Audio Controller (rev 04
  9. 00:1c.0 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 3 (rev e4) 
  10. 00:1c.3 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 4 (rev e4) 
  11. 00:1c.4 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 5 (rev e4) 
  12. 00:1d.0 USB controller: Intel Corporation Lynx Point-LP USB EHCI #1 (rev 04
  13. 00:1f.0 ISA bridge: Intel Corporation Lynx Point-LP LPC Controller (rev 04
  14. 00:1f.2 SATA controller: Intel Corporation Lynx Point-LP SATA Controller 1 [AHCI mode] (rev 04
  15. 00:1f.3 SMBus: Intel Corporation Lynx Point-LP SMBus Controller (rev 04
  16. 01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 10
  17. 02:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter 
  18. 03:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 840M] (rev a2) 

使用-t选项将以树的形式生成输出。

 

  1. tecmint@tecmint ~ $ lspci -t 
  2.  
  3. -[0000:00]-+-00.0 
  4.            +-02.0 
  5.            +-03.0 
  6.            +-14.0 
  7.            +-16.0 
  8.            +-1b.0 
  9.            +-1c.0-[01]----00.0 
  10.            +-1c.3-[02]----00.0 
  11.            +-1c.4-[03]----00.0 
  12.            +-1d.0 
  13.            +-1f.0 
  14.            +-1f.2 
  15.            \-1f.3 

使用-v选项生成有关每个连接的设备的详细信息。

 

  1. tecmint@tecmint ~ $ lspci -v 
  2.  
  3. 00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b) 
  4. Subsystem: Lenovo Device 3978 
  5. Flags: bus master, fast devsel, latency 0 
  6. Capabilities: 
  7.  
  8. 00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b) (prog-if 00 [VGA controller]) 
  9. Subsystem: Lenovo Device 380d 
  10. Flags: bus master, fast devsel, latency 0, IRQ 62 
  11. Memory at c3000000 (64-bit, non-prefetchable) [size=4M] 
  12. Memory at d0000000 (64-bit, prefetchable) [size=256M] 
  13. I/O ports at 6000 [size=64
  14. Expansion ROM at  [disabled] 
  15. Capabilities: 
  16. Kernel driver in use: i915 
  17. ..... 

7.如何输出SCSI设备的信息

要查看所有的scsi / sata设备,可使用lsscsi命令,如下所示。如果你没有安装lsscsi工具,那么运行下面的命令来安装它。

  1. $ sudo apt-get install lsscsi        [on Debian derivatives] 
  2. # yum install lsscsi                 [On RedHat based systems] 
  3. # dnf install lsscsi                 [On Fedora 21+ Onwards] 

安装后,运行lsscsi命令,如下所示:

 

  1. tecmint@tecmint ~ $ lsscsi 
  2.  
  3. [0:0:0:0]    disk    ATA      ST1000LM024 HN-M 2BA3  /dev/sda 
  4. [1:0:0:0]    cd/dvd  PLDS     DVD-RW DA8A5SH   RL61  /dev/sr0 
  5. [4:0:0:0]    disk    Generic- xD/SD/M.S.       1.00  /dev/sdb 

使用-s选项来显示设备尺寸。

 

  1. tecmint@tecmint ~ $ lsscsi -s 
  2.  
  3. [0:0:0:0]    disk    ATA      ST1000LM024 HN-M 2BA3  /dev/sda   1.00TB 
  4. [1:0:0:0]    cd/dvd  PLDS     DVD-RW DA8A5SH   RL61  /dev/sr0        - 
  5. [4:0:0:0]    disk    Generic- xD/SD/M.S.       1.00  /dev/sdb        - 

8.如何打印有关SATA设备的信息

你可以使用hdparm实用工具在系统上找到有关sata设备的一些信息,如下所示。在下面的例子中,我使用了块设备/ dev / sda1。

 

  1. tecmint@tecmint ~ $ sudo hdparm /dev/sda1 
  2.  
  3. /dev/sda1: 
  4. multcount     =  0 (off) 
  5. IO_support    =  1 (32-bit) 
  6. readonly      =  0 (off) 
  7. readahead     = 256 (on) 
  8. geometry      = 56065/255/63, sectors = 2048000, start = 2048 

要输出设备有关柱面、磁头、扇区、大小和起始偏移量的几何信息,使用-g选项。

 

  1. tecmint@tecmint ~ $ sudo hdparm -g /dev/sda1 
  2.  
  3. /dev/sda1: 
  4. geometry      = 56065/255/63, sectors = 2048000, start = 2048 

9.如何输出Linux文件系统信息

为了收集有关文件系统分区的信息,你可以使用fdisk命令。虽然fdisk命令的主要功能是修改文件系统分区,但我们也可以用它来查看文件系统上不同分区的信息。

你可以按如下方法输出分区信息。记住要用超级用户的身份运行命令,否则你可能看不到任何输出。

 

  1. tecmint@tecmint ~ $ sudo fdisk -l 
  2.  
  3. WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted. 
  4.  
  5. Disk /dev/sda: 1000.2 GB, 1000204886016 bytes 
  6. 255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors 
  7. Units = sectors of 1 * 512 = 512 bytes 
  8. Sector size (logical/physical): 512 bytes / 4096 bytes 
  9. I/O size (minimum/optimal): 4096 bytes / 4096 bytes 
  10. Disk identifier: 0xcee8ad92 
  11.  
  12.    Device Boot      Start         End      Blocks   Id  System 
  13. /dev/sda1               1  1953525167   976762583+  ee  GPT 
  14. Partition 1 does not start on physical sector boundary. 

10.如何提取有关硬件组件的信息

你也可以使用dmidecode实用程序通过读取DMI表中的数据提取硬件信息。

输出有关内存的信息,作为超级用户运行此命令。

  1. tecmint@tecmint ~ $ sudo dmidecode -t memory 
  2.  
  3. # dmidecode 2.12 
  4. # SMBIOS entry point at 0xaaebef98 
  5. SMBIOS 2.7 present. 
  6.  
  7. Handle 0x0005, DMI type 524 bytes 
  8. Memory Controller Information 
  9. Error Detecting Method: None 
  10. Error Correcting Capabilities: 
  11.   None 
  12. Supported Interleave: One-way Interleave 
  13. Current Interleave: One-way Interleave 
  14. Maximum Memory Module Size: 8192 MB 
  15. Maximum Total Memory Size: 32768 MB 
  16. Supported Speeds: 
  17.   Other 
  18. Supported Memory Types: 
  19.   Other 
  20. Memory Module Voltage: Unknown 
  21. Associated Memory Slots: 4 
  22.   0x0006 
  23.   0x0007 
  24.   0x0008 
  25.   0x0009 
  26. Enabled Error Correcting Capabilities: 
  27.   None 
  28. ... 

要输出有关系统的信息,运行此命令。

 

  1. tecmint@tecmint ~ $ sudo dmidecode -t system 
  2.  
  3. # dmidecode 2.12 
  4. # SMBIOS entry point at 0xaaebef98 
  5. SMBIOS 2.7 present. 
  6.  
  7. Handle 0x0001, DMI type 127 bytes 
  8. System Information 
  9. Manufacturer: LENOVO 
  10. Product Name: 20354 
  11. Version: Lenovo Z50-70 
  12. Serial Number: 1037407803441 
  13. UUID: 29D2B1E4-37D2-11E4-9F6E-28D244EBBD98 
  14. Wake-up Type: Power Switch 
  15. SKU Number: LENOVO_MT_20354_BU_idea_FM_Lenovo Z50-70 
  16. Family: IDEAPAD 
  17. ... 

要输出有关BIOS的信息,运行此命令。

 

  1. tecmint@tecmint ~ $ sudo dmidecode -t bios 
  2.  
  3. # dmidecode 2.12 
  4. # SMBIOS entry point at 0xaaebef98 
  5. SMBIOS 2.7 present. 
  6.  
  7. Handle 0x0000, DMI type 024 bytes 
  8. BIOS Information 
  9. Vendor: LENOVO 
  10. Version: 9BCN26WW 
  11. Release Date: 07/31/2014 
  12. Address: 0xE0000 
  13. Runtime Size: 128 kB 
  14. ROM Size: 4096 kB 
  15. Characteristics: 
  16.   PCI is supported 
  17.   BIOS is upgradeable 
  18.   BIOS shadowing is allowed 
  19.   Boot from CD is supported 
  20.   Selectable boot is supported 
  21.   EDD is supported 
  22.   Japanese floppy for NEC 9800 1.2 MB is supported (int 13h) 
  23.   Japanese floppy for Toshiba 1.2 MB is supported (int 13h) 
  24.   5.25"/360 kB floppy services are supported (int 13h) 
  25.   5.25"/1.2 MB floppy services are supported (int 13h) 
  26.   3.5"/720 kB floppy services are supported (int 13h) 
  27.   3.5"/2.88 MB floppy services are supported (int 13h) 
  28.   8042 keyboard services are supported (int 9h) 
  29.   CGA/mono video services are supported (int 10h) 
  30.   ACPI is supported 
  31.   USB legacy is supported 
  32.   BIOS boot specification is supported 
  33.   Targeted content distribution is supported 
  34.   UEFI is supported 
  35. BIOS Revision: 0.26 
  36. Firmware Revision: 0.26 
  37. ... 

要输出关于处理器的信息,运行此命令。

  1. tecmint@tecmint ~ $ sudo dmidecode -t processor 
  2.  
  3. # dmidecode 2.12 
  4. # SMBIOS entry point at 0xaaebef98 
  5. SMBIOS 2.7 present. 
  6.  
  7. Handle 0x0004, DMI type 442 bytes 
  8. Processor Information 
  9. Socket Designation: U3E1 
  10. Type: Central Processor 
  11. Family: Core i5 
  12. Manufacturer: Intel(R) Corporation 
  13. ID: 51 06 04 00 FF FB EB BF 
  14. Signature: Type 0, Family 6, Model 69, Stepping 1 
  15. Flags: 
  16. ... 

总结

还有很多其他的方法能让你用来获取有关系统硬件组件的信息。这些命令中的大多数使用/ proc目录下的文件来提取系统信息。

希望这些方法和技巧能对你有用,如果你有任何其他看法的话,欢迎留言评论。

译文链接:http://www.codeceo.com/article/10-linux-command-collect-info.html
英文原文:10 Useful Commands to Collect System and Hardware Information in Linux

 

责任编辑:王雪燕 来源: 码农网
相关推荐

2015-09-23 09:22:01

系统硬件命令

2014-05-15 10:49:09

Linux 硬件信息Linux 命令

2014-05-04 10:34:32

Linux硬件信息Linux命令

2021-04-09 11:42:16

Linux 系统硬件操作系统

2011-07-19 09:25:52

2010-03-02 14:01:58

Linux硬件信息命令

2018-09-13 10:00:02

Linux命令危险命令

2017-03-20 14:37:43

Linux命令

2014-03-17 17:27:51

Linux mvLinux 命令

2018-01-08 15:50:21

Linux命令系统和硬件

2013-09-29 10:14:24

YUM软件包管理Linux YUM

2018-09-17 11:55:21

Linux命令管理进程

2009-12-11 15:47:54

Linux硬件信息

2014-04-08 15:05:11

LinuxLinux命令行补全命令

2018-04-20 09:58:10

Linux命令sudo

2013-12-23 11:01:14

命令Linux命令

2014-03-18 14:00:19

Linux监控命令

2009-09-25 10:48:07

Linux硬件信息操作系统

2020-05-13 09:22:51

Linux开源缓存工具

2014-08-13 10:15:00

Linuxdmesg命令
点赞
收藏

51CTO技术栈公众号