1818IP-服务器技术教程,云服务器评测推荐,服务器系统排错处理,环境搭建,攻击防护等

当前位置:首页 - 运维 - 正文

君子好学,自强不息!

Linux硬件信息命令大全

2022-11-06 | 运维 | admin | 612°c
A+ A-

硬件信息

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

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

1. lscpu

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

$lscpu
Architecture:x86_64
CPUop-mode(s):32-bit,64-bit
ByteOrder:LittleEndian
CPU(s):4
On-lineCPU(s)list:0-3
Thread(s)percore:1
Core(s)persocket:4
Socket(s):1
NUMAnode(s):1
VendorID:GenuineIntel
CPUfamily:6
Model:23
Stepping:10
CPUMHz:1998.000
BogoMIPS:5302.48
Virtualization:VT-x
L1dcache:32K
L1icache:32K
L2cache:2048K
NUMAnode0CPU(s):0-3

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

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

$sudolshw-short

H/WpathDeviceClassDescription
===================================================
system()
/0busDG35EC
/0/0processorIntel(R)Core(TM)2QuadCPUQ8400@2.66GHz
/0/0/1memory2MiBL2cache
/0/0/3memory32KiBL1cache
/0/2memory32KiBL1cache
/0/4memory64KiBBIOS
/0/14memory8GiBSystemMemory
/0/14/0memory2GiBDIMMDDR2Synchronous667MHz(1.5ns)
/0/14/1memory2GiBDIMMDDR2Synchronous667MHz(1.5ns)
/0/14/2memory2GiBDIMMDDR2Synchronous667MHz(1.5ns)
/0/14/3memory2GiBDIMMDDR2Synchronous667MHz(1.5ns)
/0/100bridge82G35ExpressDRAMController
/0/100/2display82G35ExpressIntegratedGraphicsController
/0/100/2.1display82G35ExpressIntegratedGraphicsController
/0/100/19eth0network82566DCGigabitNetworkConnection
/0/100/1abus82801H(ICH8Family)USBUHCIController#4
/0/100/1a.1bus82801H(ICH8Family)USBUHCIController#5
/0/100/1a.7bus82801H(ICH8Family)USB2EHCIController#2
/0/100/1bmultimedia82801H(ICH8Family)HDAudioController
/0/100/1cbridge82801H(ICH8Family)PCIExpressPort1
/0/100/1c.1bridge82801H(ICH8Family)PCIExpressPort2
/0/100/1c.2bridge82801H(ICH8Family)PCIExpressPort3
/0/100/1c.2/0storageJMB368IDEcontroller
/0/100/1dbus82801H(ICH8Family)USBUHCIController#1
/0/100/1d.1bus82801H(ICH8Family)USBUHCIController#2
/0/100/1d.2bus82801H(ICH8Family)USBUHCIController#3
/0/100/1d.7bus82801H(ICH8Family)USB2EHCIController#1
/0/100/1ebridge82801PCIBridge
/0/100/1e/5busFW322/323[TrueFire]1394aController
/0/100/1fbridge82801HB/HR(ICH8/R)LPCInterfaceController
/0/100/1f.2storage82801H(ICH8Family)4portSATAController[IDEmode]
/0/100/1f.3bus82801H(ICH8Family)SMBusController
/0/100/1f.5storage82801HR/HO/HH(ICH8R/DO/DH)2portSATAController[IDEm
/0/1scsi3storage
/0/1/0.0.0/dev/sdadisk500GBST3500418AS
/0/1/0.0.0/1/dev/sda1volume70GiBWindowsNTFSvolume
/0/1/0.0.0/2/dev/sda2volume395GiBExtendedpartition
/0/1/0.0.0/2/5/dev/sda5volume97GiBHPFS/NTFSpartition
/0/1/0.0.0/2/6/dev/sda6volume97GiBLinuxfilesystempartition
/0/1/0.0.0/2/7/dev/sda7volume1952MiBLinuxswap/Solarispartition
/0/1/0.0.0/2/8/dev/sda8volume198GiBLinuxfilesystempartition
/0/3scsi4storage
/0/3/0.0.0/dev/cdromdiskDVDRWDRU-190A

点击下面的帖子,可以对lshw有更多的了解。

在Linux上使用lshw命令获取硬件信息

3. hwinfo – Hardware Information

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

$hwinfo--short
cpu:
Intel(R)Core(TM)2QuadCPUQ8400@2.66GHz,2000MHz
Intel(R)Core(TM)2QuadCPUQ8400@2.66GHz,2000MHz
Intel(R)Core(TM)2QuadCPUQ8400@2.66GHz,2666MHz
Intel(R)Core(TM)2QuadCPUQ8400@2.66GHz,2666MHz
keyboard:
/dev/input/event2ATTranslatedSet2keyboard
mouse:
/dev/input/miceMicrosoftBasicOpticalMousev2.0
graphicscard:
Intel965G-1
Intel82G35ExpressIntegratedGraphicsController
sound:
Intel82801H(ICH8Family)HDAudioController
storage:
Intel82801H(ICH8Family)4portSATAIDEController
Intel82801H(ICH8Family)2portSATAIDEController
JMicronJMB368IDEcontroller
network:
eth0Intel82566DCGigabitNetworkConnection
networkinterface:
eth0Ethernetnetworkinterface
loLoopbacknetworkinterface
disk:
/dev/sdaST3500418AS
partition:
/dev/sda1Partition
/dev/sda2Partition
/dev/sda5Partition
/dev/sda6Partition
/dev/sda7Partition
/dev/sda8Partition
cdrom:
/dev/sr0SONYDVDRWDRU-190A
usbcontroller:
Intel82801H(ICH8Family)USBUHCIController#4
Intel82801H(ICH8Family)USBUHCIController#5
Intel82801H(ICH8Family)USB2EHCIController#2
Intel82801H(ICH8Family)USBUHCIController#1
Intel82801H(ICH8Family)USBUHCIController#2
Intel82801H(ICH8Family)USBUHCIController#3
Intel82801H(ICH8Family)USB2EHCIController#1
bios:
BIOS
...TRUNCATED...

点击下面的链接可以查看更多关于hwinfo的信息。

在Linux上使用hwinfo命令获取硬件信息

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

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

$lspci
00:00.0Hostbridge:IntelCorporation82G35ExpressDRAMController(rev03)
00:02.0VGAcompatiblecontroller:IntelCorporation82G35ExpressIntegratedGraphicsController(rev03)
00:02.1Displaycontroller:IntelCorporation82G35ExpressIntegratedGraphicsController(rev03)
00:19.0Ethernetcontroller:IntelCorporation82566DCGigabitNetworkConnection(rev02)
00:1a.0USBcontroller:IntelCorporation82801H(ICH8Family)USBUHCIController#4(rev02)
00:1a.1USBcontroller:IntelCorporation82801H(ICH8Family)USBUHCIController#5(rev02)
00:1a.7USBcontroller:IntelCorporation82801H(ICH8Family)USB2EHCIController#2(rev02)
00:1b.0Audiodevice:IntelCorporation82801H(ICH8Family)HDAudioController(rev02)
00:1c.0PCIbridge:IntelCorporation82801H(ICH8Family)PCIExpressPort1(rev02)
00:1c.1PCIbridge:IntelCorporation82801H(ICH8Family)PCIExpressPort2(rev02)
00:1c.2PCIbridge:IntelCorporation82801H(ICH8Family)PCIExpressPort3(rev02)
00:1d.0USBcontroller:IntelCorporation82801H(ICH8Family)USBUHCIController#1(rev02)
00:1d.1USBcontroller:IntelCorporation82801H(ICH8Family)USBUHCIController#2(rev02)
00:1d.2USBcontroller:IntelCorporation82801H(ICH8Family)USBUHCIController#3(rev02)
00:1d.7USBcontroller:IntelCorporation82801H(ICH8Family)USB2EHCIController#1(rev02)
00:1e.0PCIbridge:IntelCorporation82801PCIBridge(revf2)
00:1f.0ISAbridge:IntelCorporation82801HB/HR(ICH8/R)LPCInterfaceController(rev02)
00:1f.2IDEinterface:IntelCorporation82801H(ICH8Family)4portSATAController[IDEmode](rev02)
00:1f.3SMBus:IntelCorporation82801H(ICH8Family)SMBusController(rev02)
00:1f.5IDEinterface:IntelCorporation82801HR/HO/HH(ICH8R/DO/DH)2portSATAController[IDEmode](rev02)
03:00.0IDEinterface:JMicronTechnologyCorp.JMB368IDEcontroller
04:05.0FireWire(IEEE1394):LSICorporationFW322/323[TrueFire]1394aController(rev70)

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

$lspci-v|grep"VGA"-A12

5. lsscsi – 列出scsi设备信息

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

$lsscsi
[3:0:0:0]diskATAST3500418ASCC38/dev/sda
[4:0:0:0]cd/dvdSONYDVDRWDRU-190A1.63/dev/sr0

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

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

$lsusb
Bus002Device001:ID1d6b:0002LinuxFoundation2.0roothub
Bus007Device001:ID1d6b:0001LinuxFoundation1.1roothub
Bus006Device001:ID1d6b:0001LinuxFoundation1.1roothub
Bus005Device002:ID045e:00cbMicrosoftCorp.BasicOpticalMousev2.0
Bus005Device001:ID1d6b:0001LinuxFoundation1.1roothub
Bus001Device001:ID1d6b:0002LinuxFoundation2.0roothub
Bus004Device001:ID1d6b:0001LinuxFoundation1.1roothub
Bus003Device001:ID1d6b:0001LinuxFoundation1.1roothub

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

7. Inxi

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

$inxi-Fx

8. lsblk – 列出块设备信息

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

$lsblk
NAMEMAJ:MINRMSIZEROTYPEMOUNTPOINT
sda8:00465.8G0disk
├─sda18:1070G0part
├─sda28:201K0part
├─sda58:5097.7G0part/media/4668484A68483B47
├─sda68:6097.7G0part/
├─sda78:701.9G0part[SWAP]
└─sda88:80198.5G0part/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
sr011:011024M0rom

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

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

$df-H
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda6104G26G73G26%/
none4.1k04.1k0%/sys/fs/cgroup
udev4.2G4.1k4.2G1%/dev
tmpfs837M1.6M835M1%/run
none5.3M05.3M0%/run/lock
none4.2G13M4.2G1%/run/shm
none105M21k105M1%/run/user
/dev/sda8210G149G51G75%/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda5105G31G75G30%/media/4668484A68483B47

10. pydf – python版本的df

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

$pydf
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda696G23G68G24.4[#.....]/
/dev/sda8195G138G47G70.6[####..]/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda598G28G69G29.2[##....]/media/4668484A68483B47

11. fdisk

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

$sudofdisk-l
Disk/dev/sda:500.1GB,500107862016bytes
255heads,63sectors/track,60801cylinders,total976773168sectors
Units=sectorsof1*512512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x30093008
DeviceBootStartEndBlocksIdSystem
/dev/sda1*6314680196973400953+7HPFS/NTFS/exFAT
/dev/sda2146802031976771071414984520+fW95Ext'd(LBA)
/dev/sda51468020333516146541024063117HPFS/NTFS/exFAT
/dev/sda635161471855642733910240631183Linux
/dev/sda7556429312560427007199884882Linuxswap/Solaris
/dev/sda856042905697677107120817100883Linux

12. mount

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

$mount|column-t
/dev/sda6on/typeext4(rw,errors=remount-ro)
procon/proctypeproc(rw,noexec,nosuid,nodev)
sysfson/systypesysfs(rw,noexec,nosuid,nodev)
noneon/sys/fs/cgrouptypetmpfs(rw)
noneon/sys/fs/fuse/connectionstypefusectl(rw)
noneon/sys/kernel/debugtypedebugfs(rw)
noneon/sys/kernel/securitytypesecurityfs(rw)
udevon/devtypedevtmpfs(rw,mode=0755)
devptson/dev/ptstypedevpts(rw,noexec,nosuid,gid=5,mode=0620)
tmpfson/runtypetmpfs(rw,noexec,nosuid,size=10%,mode=0755)
noneon/run/locktypetmpfs(rw,noexec,nosuid,nodev,size=5242880)
noneon/run/shmtypetmpfs(rw,nosuid,nodev)
noneon/run/usertypetmpfs(rw,noexec,nosuid,nodev,size=104857600,mode=0755)
noneon/sys/fs/pstoretypepstore(rw)
/dev/sda8on/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1typeext4(rw,nosuid,nodev,errors=remount-ro)
/dev/sda5on/media/4668484A68483B47typefuseblk(rw,nosuid,nodev,allow_other,blksize=4096)
binfmt_miscon/proc/sys/fs/binfmt_misctypebinfmt_misc(rw,noexec,nosuid,nodev)
systemdon/sys/fs/cgroup/systemdtypecgroup(rw,noexec,nosuid,nodev,none,name=systemd)
gvfsd-fuseon/run/user/1000/gvfstypefuse.gvfsd-fuse(rw,nosuid,nodev,user=enlightened)

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

$mount|column-t|grepext

13. free – 查看RAM信息

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

$free-m
totalusedfreesharedbufferscached
Mem:797558652110024622
-/+buffers/cache:52182757
Swap:19519211030

14. dmidecode

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

#显示处理器信息
$sudodmidecode-tprocessor
#显示内存信息
$sudodmidecode-tmemory
#显示bios信息
$sudodmidecode-tbios

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

15. /proc 文件系统

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

CPU、内存信息

#cpu信息
$cat/proc/cpuinfo
#内存信息
$cat/proc/meminfo

Linux内核信息

$cat/proc/version
Linuxversion3.11.0-12-generic(buildd@allspice)(gccversion4.8.1(Ubuntu/Linaro4.8.1-10ubuntu7))#19-UbuntuSMPWedOct916:20:46UTC2013

SCSI/Sata设备信息

$cat/proc/scsi/scsi
Attacheddevices:
Host:scsi3Channel:00Id:00Lun:00
Vendor:ATAModel:ST3500418ASRev:CC38
Type:Direct-AccessANSISCSIrevision:05
Host:scsi4Channel:00Id:00Lun:00
Vendor:SONYModel:DVDRWDRU-190ARev:1.63
Type:CD-ROMANSISCSIrevision:05

分区信息

$cat/proc/partitions
majorminor#blocksname

80488386584sda
8173400953sda1
821sda2
85102406311sda5
86102406311sda6
871998848sda7
88208171008sda8
1101048575sr0

16. hdparm

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

$sudohdparm-i/dev/sda
/dev/sda:
Model=ST3500418AS,FwRev=CC38,SerialNo=9VMJXV1N
Config={HardSectNotMFMHdSw>15uSecFixedDTR>10MbsRotSpdTol>.5%}
RawCHS=16383/16/63,TrkSize=0,SectSize=0,ECCbytes=4
BuffType=unknown,BuffSize=16384kB,MaxMultSect=16,MultSect=16
CurCHS=16383/16/63,CurSects=16514064,LBA=yes,LBAsects=976773168
IORDY=on/off,tPIO={min:120,w/IORDY:120},tDMA={min:120,rec:120}
PIOmodes:pio0pio1pio2pio3pio4
DMAmodes:mdma0mdma1mdma2
UDMAmodes:udma0udma1udma2udma3udma4udma5*udma6
AdvancedPM=noWriteCache=enabled
Driveconformsto:unknown:ATA/ATAPI-4,5,6,7
*signifiesthecurrentactivemode

总结

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

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


本文来源:1818IP

本文地址:https://www.1818ip.com/post/7364.html

免责声明:本文由用户上传,如有侵权请联系删除!

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。