Linux硬件信息命令大全

Linux硬件信息命令大全


       在linux系统中,有很多命令可以用于查询主机的硬件信息,有些命令仅仅针对于特定的硬件部件,比如cpu,内存等,而有些命令可以查询很多的硬件信息。

这篇帖子简单地带大家了解一下最常用的查询各种硬件信息的命令,其中包括lscpu,hwinfo,lshw,dmidecode,lspci等等。

1. lscpu

      lscpu命令可以用来查询处理器cpu的详细信息,只需要简单地输入lscpu即可,如下所示,它本身也没有提供更多选项和功能可供选择。

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




2. lshw - 显示硬件信息列表

      这个命令用途广泛,它可以根据你的需求以详细或概要的形式列出许多个不同硬件的参数信息,其中包括cpu,内存,磁盘,usb控制器,网卡等等,lshw实质上是从/proc文件目录下的不同文件中提取对应的硬件信息。

 
 
  1. $ sudo lshw -short
  2.  
  3. H/W path Device Class Description
  4. ===================================================
  5. system ()
  6. /0 bus DG35EC
  7. /0/0 processor Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz
  8. /0/0/1 memory 2MiB L2 cache
  9. /0/0/3 memory 32KiB L1 cache
  10. /0/2 memory 32KiB L1 cache
  11. /0/4 memory 64KiB BIOS
  12. /0/14 memory 8GiB System Memory
  13. /0/14/0 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
  14. /0/14/1 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
  15. /0/14/2 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
  16. /0/14/3 memory 2GiB DIMM DDR2 Synchronous 667 MHz (1.5 ns)
  17. /0/100 bridge 82G35 Express DRAM Controller
  18. /0/100/2 display 82G35 Express Integrated Graphics Controller
  19. /0/100/2.1 display 82G35 Express Integrated Graphics Controller
  20. /0/100/19 eth0 network 82566DC Gigabit Network Connection
  21. /0/100/1a bus 82801H (ICH8 Family) USB UHCI Controller #4
  22. /0/100/1a.1 bus 82801H (ICH8 Family) USB UHCI Controller #5
  23. /0/100/1a.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #2
  24. /0/100/1b multimedia 82801H (ICH8 Family) HD Audio Controller
  25. /0/100/1c bridge 82801H (ICH8 Family) PCI Express Port 1
  26. /0/100/1c.1 bridge 82801H (ICH8 Family) PCI Express Port 2
  27. /0/100/1c.2 bridge 82801H (ICH8 Family) PCI Express Port 3
  28. /0/100/1c.2/0 storage JMB368 IDE controller
  29. /0/100/1d bus 82801H (ICH8 Family) USB UHCI Controller #1
  30. /0/100/1d.1 bus 82801H (ICH8 Family) USB UHCI Controller #2
  31. /0/100/1d.2 bus 82801H (ICH8 Family) USB UHCI Controller #3
  32. /0/100/1d.7 bus 82801H (ICH8 Family) USB2 EHCI Controller #1
  33. /0/100/1e bridge 82801 PCI Bridge
  34. /0/100/1e/5 bus FW322/323 [TrueFire] 1394a Controller
  35. /0/100/1f bridge 82801HB/HR (ICH8/R) LPC Interface Controller
  36. /0/100/1f.2 storage 82801H (ICH8 Family) 4 port SATA Controller [IDE mode]
  37. /0/100/1f.3 bus 82801H (ICH8 Family) SMBus Controller
  38. /0/100/1f.5 storage 82801HR/HO/HH (ICH8R/DO/DH) 2 port SATA Controller [IDE m
  39. /0/1 scsi3 storage
  40. /0/1/0.0.0 /dev/sda disk 500GB ST3500418AS
  41. /0/1/0.0.0/1 /dev/sda1 volume 70GiB Windows NTFS volume
  42. /0/1/0.0.0/2 /dev/sda2 volume 395GiB Extended partition
  43. /0/1/0.0.0/2/5 /dev/sda5 volume 97GiB HPFS/NTFS partition
  44. /0/1/0.0.0/2/6 /dev/sda6 volume 97GiB Linux filesystem partition
  45. /0/1/0.0.0/2/7 /dev/sda7 volume 1952MiB Linux swap / Solaris partition
  46. /0/1/0.0.0/2/8 /dev/sda8 volume 198GiB Linux filesystem partition
  47. /0/3 scsi4 storage
  48. /0/3/0.0.0 /dev/cdrom disk DVD RW DRU-190A




3. hwinfo - Hardware Information

      hwinfo同样是一个使用非常广泛的硬件信息查询命令,类似于lshw,它同样可以详细或概要地报告多个部件的硬件信息,但不同的是,它有时可以给出比lshw更多的信息。

 
 
  1. $ hwinfo --short
  2. cpu:
  3. Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2000 MHz
  4. Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2000 MHz
  5. Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2666 MHz
  6. Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz, 2666 MHz
  7. keyboard:
  8. /dev/input/event2 AT Translated Set 2 keyboard
  9. mouse:
  10. /dev/input/mice Microsoft Basic Optical Mouse v2.0
  11. graphics card:
  12. Intel 965G-1
  13. Intel 82G35 Express Integrated Graphics Controller
  14. sound:
  15. Intel 82801H (ICH8 Family) HD Audio Controller
  16. storage:
  17. Intel 82801H (ICH8 Family) 4 port SATA IDE Controller
  18. Intel 82801H (ICH8 Family) 2 port SATA IDE Controller
  19. JMicron JMB368 IDE controller
  20. network:
  21. eth0 Intel 82566DC Gigabit Network Connection
  22. network interface:
  23. eth0 Ethernet network interface
  24. lo Loopback network interface
  25. disk:
  26. /dev/sda ST3500418AS
  27. partition:
  28. /dev/sda1 Partition
  29. /dev/sda2 Partition
  30. /dev/sda5 Partition
  31. /dev/sda6 Partition
  32. /dev/sda7 Partition
  33. /dev/sda8 Partition
  34. cdrom:
  35. /dev/sr0 SONY DVD RW DRU-190A
  36. usb controller:
  37. Intel 82801H (ICH8 Family) USB UHCI Controller #4
  38. Intel 82801H (ICH8 Family) USB UHCI Controller #5
  39. Intel 82801H (ICH8 Family) USB2 EHCI Controller #2
  40. Intel 82801H (ICH8 Family) USB UHCI Controller #1
  41. Intel 82801H (ICH8 Family) USB UHCI Controller #2
  42. Intel 82801H (ICH8 Family) USB UHCI Controller #3
  43. Intel 82801H (ICH8 Family) USB2 EHCI Controller #1
  44. bios:
  45. BIOS
  46.  
  47. ... TRUNCATED ...


4. lspci - 显示pci总线相关信息

      lscpi命令可以列出pci总线上信息,以及所有连接到pci总线上的设备信息,比如VGA适配器,显卡,网卡,usb端口,sata控制器等等。

 
 
  1. $ lspci
  2. 00:00.0 Host bridge: Intel Corporation 82G35 Express DRAM Controller (rev 03)
  3. 00:02.0 VGA compatible controller: Intel Corporation 82G35 Express Integrated Graphics Controller (rev 03)
  4. 00:02.1 Display controller: Intel Corporation 82G35 Express Integrated Graphics Controller (rev 03)
  5. 00:19.0 Ethernet controller: Intel Corporation 82566DC Gigabit Network Connection (rev 02)
  6. 00:1a.0 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #4 (rev 02)
  7. 00:1a.1 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #5 (rev 02)
  8. 00:1a.7 USB controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #2 (rev 02)
  9. 00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 02)
  10. 00:1c.0 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 1 (rev 02)
  11. 00:1c.1 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 2 (rev 02)
  12. 00:1c.2 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 3 (rev 02)
  13. 00:1d.0 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #1 (rev 02)
  14. 00:1d.1 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 02)
  15. 00:1d.2 USB controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #3 (rev 02)
  16. 00:1d.7 USB controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #1 (rev 02)
  17. 00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev f2)
  18. 00:1f.0 ISA bridge: Intel Corporation 82801HB/HR (ICH8/R) LPC Interface Controller (rev 02)
  19. 00:1f.2 IDE interface: Intel Corporation 82801H (ICH8 Family) 4 port SATA Controller [IDE mode] (rev 02)
  20. 00:1f.3 SMBus: Intel Corporation 82801H (ICH8 Family) SMBus Controller (rev 02)
  21. 00:1f.5 IDE interface: Intel Corporation 82801HR/HO/HH (ICH8R/DO/DH) 2 port SATA Controller [IDE mode] (rev 02)
  22. 03:00.0 IDE interface: JMicron Technology Corp. JMB368 IDE controller
  23. 04:05.0 FireWire (IEEE 1394): LSI Corporation FW322/323 [TrueFire] 1394a Controller (rev 70)

      可以使用grep命令筛选出特定的设备信息。

 
 
  1. $ lspci -v | grep "VGA" -A 12


5. lsscsi - 列出scsi设备信息

      列出scsi/sata设备信息,比如硬盘驱动器,光盘驱动器。

 
 
  1. $ lsscsi
  2. [3:0:0:0] disk ATA ST3500418AS CC38 /dev/sda
  3. [4:0:0:0] cd/dvd SONY DVD RW DRU-190A 1.63 /dev/sr0


6. lsusb - 列出usb总线信息,及设备信息

      该命令可以显示USB控制器及连接到控制的设备信息。默认情况下,只显示概要信息,可以通过-v选项指示其显示更多的硬件信息。

 
 
  1. $ lsusb
  2. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  3. Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  4. Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  5. Bus 005 Device 002: ID 045e:00cb Microsoft Corp. Basic Optical Mouse v2.0
  6. Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  7. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  8. Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  9. Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

      上面信息显示,在该系统中,有一个usb端口正被鼠标占用。


7. Inxi

      inxi命令是一个大的bash脚本文件,其通过从不同的信息来源和命令中获取硬件信息,最后能给出一个颜色高亮的,适合于非专业人员阅读的硬件信息报告。

 
 
  1. $ inxi -Fx




8. lsblk - 列出块设备信息

      列出所有块设备信息,其中包括硬盘分区信息,以及其他存储设备,如光盘,闪存等。

 
 
  1. $ lsblk
  2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  3. sda 8:0 0 465.8G 0 disk
  4. ├─sda1 8:1 0 70G 0 part
  5. ├─sda2 8:2 0 1K 0 part
  6. ├─sda5 8:5 0 97.7G 0 part /media/4668484A68483B47
  7. ├─sda6 8:6 0 97.7G 0 part /
  8. ├─sda7 8:7 0 1.9G 0 part [SWAP]
  9. └─sda8 8:8 0 198.5G 0 part /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
  10. sr0 11:0 1 1024M 0 rom


9. df - 显示文件系统的磁盘空间信息

报告各种挂载的文件系统信息,其中包括挂载点,已用的,可用的磁盘空间。

 
 
  1. $ df -H
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/sda6 104G 26G 73G 26% /
  4. none 4.1k 0 4.1k 0% /sys/fs/cgroup
  5. udev 4.2G 4.1k 4.2G 1% /dev
  6. tmpfs 837M 1.6M 835M 1% /run
  7. none 5.3M 0 5.3M 0% /run/lock
  8. none 4.2G 13M 4.2G 1% /run/shm
  9. none 105M 21k 105M 1% /run/user
  10. /dev/sda8 210G 149G 51G 75% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
  11. /dev/sda5 105G 31G 75G 30% /media/4668484A68483B47


10. pydf - python版本的df

一个增强型的python版的df命令,可以以不同的颜色显示所查询的信息,看起来比df更好看。

 
 
  1. $ pydf
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/sda6 96G 23G 68G 24.4 [#.....] /
  4. /dev/sda8 195G 138G 47G 70.6 [####..] /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
  5. /dev/sda5 98G 28G 69G 29.2 [##....] /media/4668484A68483B47


11. fdisk

fdisk命令可以用来修改硬盘分区表信息,也可以用来显示硬盘分区表信息

 
 
  1. $ sudo fdisk -l
  2.  
  3. Disk /dev/sda: 500.1 GB, 500107862016 bytes
  4. 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
  5. Units = sectors of 1 * 512 = 512 bytes
  6. Sector size (logical/physical): 512 bytes / 512 bytes
  7. I/O size (minimum/optimal): 512 bytes / 512 bytes
  8. Disk identifier: 0x30093008
  9.  
  10. Device Boot Start End Blocks Id System
  11. /dev/sda1 * 63 146801969 73400953+ 7 HPFS/NTFS/exFAT
  12. /dev/sda2 146802031 976771071 414984520+ f W95 Ext'd (LBA)
  13. /dev/sda5 146802033 351614654 102406311 7 HPFS/NTFS/exFAT
  14. /dev/sda6 351614718 556427339 102406311 83 Linux
  15. /dev/sda7 556429312 560427007 1998848 82 Linux swap / Solaris
  16. /dev/sda8 560429056 976771071 208171008 83 Linux


12. mount

mount命令可以用来挂载设备,当然也可以用来查看系统中设备的挂载情况。

 
 
  1. $ mount | column -t
  2. /dev/sda6 on / type ext4 (rw,errors=remount-ro)
  3. proc on /proc type proc (rw,noexec,nosuid,nodev)
  4. sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
  5. none on /sys/fs/cgroup type tmpfs (rw)
  6. none on /sys/fs/fuse/connections type fusectl (rw)
  7. none on /sys/kernel/debug type debugfs (rw)
  8. none on /sys/kernel/security type securityfs (rw)
  9. udev on /dev type devtmpfs (rw,mode=0755)
  10. devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
  11. tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
  12. none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
  13. none on /run/shm type tmpfs (rw,nosuid,nodev)
  14. none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
  15. none on /sys/fs/pstore type pstore (rw)
  16. /dev/sda8 on /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 type ext4 (rw,nosuid,nodev,errors=remount-ro)
  17. /dev/sda5 on /media/4668484A68483B47 type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096)
  18. binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
  19. systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
  20. gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=enlightened)

同样,可以使用grep命令来筛选出想看的文件系统信息。

 
 
  1. $ mount | column -t | grep ext


13. free - 查看RAM信息

查看系统中RAM的使用情况,包括已使用空间,未使用空间,以及总空间。

 
 
  1. $ free -m
  2. total used free shared buffers cached
  3. Mem: 7975 5865 2110 0 24 622
  4. -/+ buffers/cache: 5218 2757
  5. Swap: 1951 921 1030


14. dmidecode

dmidecode命令不同于其他的命令,它是通过读取SMBOIS数据结构(也称为DMI表)中数据来提取硬件信息。

 
 
  1. # 显示处理器信息
  2. $ sudo dmidecode -t processor
  3.  
  4. # 显示内存信息
  5. $ sudo dmidecode -t memory
  6.  
  7. # 显示bios信息
  8. $ sudo dmidecode -t bios

查看man手册获取更多信息。




15. /proc 文件系统

在/proc目录下的许多虚拟文件包含了很多有关硬件参数及配置的信息。

CPU、内存信息

 
 
  1. # cpu信息
  2. $ cat /proc/cpuinfo
  3.  
  4. # 内存信息
  5. $ cat /proc/meminfo

Linux内核信息

 
 
  1. $ cat /proc/version
  2. Linux version 3.11.0-12-generic (buildd@allspice) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu7) ) #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013

SCSI/Sata设备信息

 
 
  1. $ cat /proc/scsi/scsi
  2. Attached devices:
  3. Host: scsi3 Channel: 00 Id: 00 Lun: 00
  4. Vendor: ATA Model: ST3500418AS Rev: CC38
  5. Type: Direct-Access ANSI SCSI revision: 05
  6. Host: scsi4 Channel: 00 Id: 00 Lun: 00
  7. Vendor: SONY Model: DVD RW DRU-190A Rev: 1.63
  8. Type: CD-ROM ANSI SCSI revision: 05

分区信息

 
 
  1. $ cat /proc/partitions
  2. major minor #blocks name
  3.  
  4. 8 0 488386584 sda
  5. 8 1 73400953 sda1
  6. 8 2 1 sda2
  7. 8 5 102406311 sda5
  8. 8 6 102406311 sda6
  9. 8 7 1998848 sda7
  10. 8 8 208171008 sda8
  11. 11 0 1048575 sr0



16. hdparm

hdparm命令可以获取sata设备如硬盘等设备信息。

 
 
  1. $ sudo hdparm -i /dev/sda
  2.  
  3. /dev/sda:
  4.  
  5. Model=ST3500418AS, FwRev=CC38, SerialNo=9VMJXV1N
  6. Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
  7. RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
  8. BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
  9. CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=976773168
  10. IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
  11. PIO modes: pio0 pio1 pio2 pio3 pio4
  12. DMA modes: mdma0 mdma1 mdma2
  13. UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
  14. AdvancedPM=no WriteCache=enabled
  15. Drive conforms to: unknown: ATA/ATAPI-4,5,6,7
  16.  
  17. * signifies the current active mode

总结

      每一个命令在获取信息的方式会稍微有些不同,在查询某一设备时,你也有可能要结合多个命令才能获取你想要的硬件信息。不过,这些命令都可以在大多数的linux发行版中找到,可以很容易地从默认的仓库中获取安装。

      在桌面版系统中,还有一个便于使用的图形界面的工具,比如Hardinfo、I-nex就是其中非常流行的工具,他们可以提供多个硬件部件的详细信息。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值