在Linux下,我们经常需要查看系统的硬件信息, 这里我罗列了查看系统硬件信息的实用命令,并做了分类,实例解说。
执行环境:ubuntu 16.04
1. cpu
lscpu命令,查看的是cpu的统计信息.
root@ubuntu:/home/peng/#lscpuArchitecture:x86_64#cpu架构CPUop-mode(s):32-bit,64-bitByteOrder:LittleEndian#小尾序CPU(s):1#总共有1核On-lineCPU(s)list:0Thread(s)percore:1#每个cpu核,只能支持一个线程,即不支持超线程Core(s)persocket:1Socket(s):1NUMAnode(s):1VendorID:GenuineIntel#cpu产商intelCPUfamily:6Model:158Modelname:Intel(R)Core(TM)i5-7500CPU@3.40GHzStepping:9CPUMHz:3408.070BogoMIPS:6816.14Hypervisorvendor:VMwareVirtualizationtype:full#支持cpu虚拟化技术L1dcache:32KL1icache:32KL2cache:256KL3cache:6144KNUMAnode0CPU(s):0
查看/proc/cpuinfo,可以知道每个cpu信息,如每个CPU的型号,主频等。
root@ubuntu:/home/peng#cat/proc/cpuinfoprocessor:0vendor_id:GenuineIntelcpufamily:6model:158modelname:Intel(R)Core(TM)i5-7500CPU@3.40GHzstepping:9microcode:0x48cpuMHz:3408.070cachesize:6144KBphysicalid:0siblings:1coreid:0cpucores:1apicid:0initialapicid:0fpu:yesfpu_exception:yescpuidlevel:22wp:yes…..2. 内存
概要查看内存情况
root@ubuntu:/home/peng#free-mtotalusedfreesharedbuff/cacheavailableMem:1970702315139521025Swap:97420954
这里的单位是MB,总共的内存是1970MB。
查看内存详细使用
root@ubuntu:/home/peng#cat/proc/meminfoMemTotal:2017516kBMemFree:242020kBMemAvailable:1003240kBBuffers:104192kBCached:699824kBSwapCached:1832kBActive:696320kBInactive:639924kBActive(anon):236412kBInactive(anon):301996kBActive(file):459908kBInactive(file):337928kBUnevictable:48kBMlocked:48kB…..
查看内存硬件信息
root@ubuntu:/home/peng#dmidecode-tmemory#dmidecode3.0GettingSMBIOSdatafromsysfs.SMBIOS2.7present.Handle0x0084,DMItype5,46bytesMemoryControllerInformationErrorDetectingMethod:NoneErrorCorrectingCapabilities:NoneSupportedInterleave:One-wayInterleaveCurrentInterleave:One-wayInterleaveMaximumMemoryModuleSize:32768MBMaximumTotalMemorySize:491520MBSupportedSpeeds:70ns60nsSupportedMemoryTypes:FPMEDODIMMSDRAMMemoryModuleVoltage:3.3VAssociatedMemorySlots:15…..
内存最大值是 491520 MB。
3. 磁盘
查看硬盘和分区分布
root@ubuntu:/home/peng#lsblkNAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsr011:011024M0romsda8:00500G0disk├─sda28:201K0part├─sda58:50975M0part[SWAP]└─sda18:10499G0part/
查看硬盘和分区的详细信息
root@ubuntu:/home/peng#fdisk-lDisk/dev/sda:500GiB,536870912000bytes,1048576000sectorsUnits:sectorsof1*512=512bytesSectorsize(logical/physical):512bytes/512bytesI/Osize(minimum/optimal):512bytes/512bytesDisklabeltype:dosDiskidentifier:0x9c674a44DeviceBootStartEndSectorsSizeIdType/dev/sda1*204810465751031046573056499G83Linux/dev/sda2104657715010485739511996802975M5Extended/dev/sda5104657715210485739511996800975M82Linuxswap/Solaris4. 网卡
查看网卡硬件信息
root@ubuntu:/home/peng#lspci|grep-i’eth’02:01.0Ethernetcontroller:IntelCorporation82545EMGigabitEthernetController(Copper)(rev01)
查看系统的所有网络接口
root@ubuntu:/home/peng#ifconfig-aens33Linkencap:EthernetHWaddr00:0c:29:bb:bd:40inetaddr:192.168.0.117Bcast:192.168.0.255Mask:255.255.255.0inet6addr:fe80::76fa:5548:3da0:2ef/64Scope:LinkUPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1RXpackets:174629errors:0dropped:0overruns:0frame:0TXpackets:105285errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:237519396(237.5MB)TXbytes:9592767(9.5MB)loLinkencap:LocalLoopbackinetaddr:127.0.0.1Mask:255.0.0.0inet6addr:::1/128Scope:HostUPLOOPBACKRUNNINGMTU:65536Metric:1RXpackets:854errors:0dropped:0overruns:0frame:0TXpackets:854errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:60894(60.8KB)TXbytes:60894(60.8KB)
或者是
root@ubuntu:/home/peng#iplinkshow1:lo:<LOOPBACK,UP,LOWER_UP>mtu65536qdiscnoqueuestateUNKNOWNmodeDEFAULTgroupdefaultqlen1000link/loopback00:00:00:00:00:00brd00:00:00:00:00:002:ens33:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPmodeDEFAULTgroupdefaultqlen1000link/ether00:0c:29:bb:bd:40brdff:ff:ff:ff:ff:ff
或者
如果要查看某个网络接口的详细信息,例如ens33的详细参数和指标
【有的ubuntu网口是eth0】
root@ubuntu:/home/peng#ethtoolens33Settingsforens33:Supportedports:[TP]Supportedlinkmodes:10baseT/Half10baseT/Full100baseT/Half100baseT/Full#支持千兆半双工,全双工模式1000baseT/FullSupportedpauseframeuse:NoSupportsauto-negotiation:Yes#默认使用自适应模式Advertisedlinkmodes:10baseT/Half10baseT/Full100baseT/Half100baseT/Full1000baseT/FullAdvertisedpauseframeuse:NoAdvertisedauto-negotiation:YesSpeed:1000Mb/s#网卡的速度是1000MbDuplex:Full#全双工Port:TwistedPairPHYAD:0Transceiver:internalAuto-negotiation:onMDI-X:off(auto)SupportsWake-on:dWake-on:dCurrentmessagelevel:0x00000007(7)drvprobelinkLinkdetected:yes#表示有网线连接,和路由是通的5. pci
查看pci信息,即主板所有硬件槽信息。
root@ubuntu:/home/peng#lspci00:00.0Hostbridge:IntelCorporation82845845(Brookdale)ChipsetHostBridge(rev04)00:01.0PCIbridge:IntelCorporation82845845(Brookdale)ChipsetAGPBridge(rev04)00:1d.0USBController:IntelCorporation82801CA/CAMUSB(Hub#1)(rev02)00:1d.1USBController:IntelCorporation82801CA/CAMUSB(Hub#2)(rev02)00:1e.0PCIbridge:IntelCorporation82801MobilePCIBridge(rev42)00:1f.0ISAbridge:IntelCorporation82801CAMISABridge(LPC)(rev02)00:1f.1IDEinterface:IntelCorporation82801CAMIDEU100(rev02)00:1f.3SMBus:IntelCorporation82801CA/CAMSMBusController(rev02)00:1f.5Multimediaaudiocontroller:IntelCorporation82801CA/CAMAC’97AudioController(rev02)00:1f.6Modem:IntelCorporation82801CA/CAMAC’97ModemController(rev02)01:00.0VGAcompatiblecontroller:nVidiaCorporationNV17[GeForce4420Go](reva3)02:00.0FireWire(IEEE1394):VIATechnologies,Inc.IEEE1394HostController(rev46)02:01.0Ethernetcontroller:RealtekSemiconductorCo.,Ltd.RTL-8139/8139C/8139C (rev10)02:04.0CardBusbridge:O2Micro,Inc.OZ6933CardbusController(rev01)02:04.1CardBusbridge:O2Micro,Inc.OZ6933CardbusController(rev01)
由上述的 输出可以看到,我的电脑上共有3个PCI总线(0号,1号,2号)。在单个系统上,插入多个总线是通过桥(bridge)来完成的,桥是一种用来连接总线 的特殊PCI外设。所以,PCI系统的整体布局组织为树型,我们可以通过上面的lspci输出,来画出我的电脑上的PCI系统的树型结构:
00:00.0(主桥)–00:01.0(PCI桥)—–01:00:0(nVidia显卡)||—00:1d(USB控制器)–00:1d:0(USB1号控制器)||||–00:1d:1(USB2号控制器)||-00:1e:0(PCI桥)–02:00.0(IEEE1394)||||-02:01.0(8139网卡)||||-02:04(CardBus桥)-02:04.0(桥1)||||–02:04.1(桥2)||-00:1f(多功能板卡)-00:1f:0(ISA桥)||–00:1f:1(IDE接口)||–00:1f:3(SMBus)||–00:1f:5(多媒体声音控制器)||–00:1f:6(调制解调器)
由上图可以得出,我的电脑上共有8个PCI设备,其中0号总线上(主桥)上连有4个,1号总线上连有1个,2号总线上连有3个。00:1f是一个连有5个功能的多功能板卡。
如果要更详细的信息:
lspci-v或者lspci-vv
如果要看设备树:lscpi -t
root@ubuntu:/home/peng#lspci-t6. usb
查看usb信息
root@ubuntu:/home/peng#lsusbBus001Device001:ID1d6b:0002LinuxFoundation2.0roothubBus002Device003:ID0e0f:0002VMware,Inc.VirtualUSBHubBus002Device002:ID0e0f:0003VMware,Inc.VirtualMouseBus002Device001:ID1d6b:0001LinuxFoundation1.1roothub
lsusb -t查看系统中的USB拓扑,类似cat /sys/kernel/debug/usb/devices
root@ubuntu:/home/peng#lsusb-t/:Bus02.Port1:Dev1,Class=root_hub,Driver=uhci_hcd/2p,12M|__Port1:Dev2,If0,Class=HumanInterfaceDevice,Driver=usbhid,12M|__Port2:Dev3,If0,Class=Hub,Driver=hub/7p,12M/:Bus01.Port1:Dev1,Class=root_hub,Driver=ehci-pci/6p,480M
/var/lib/usbutils/usb.ids还保存了很多设备商的VID信息
root@ubuntu:/home/peng#cat/var/lib/usbutils/usb.ids|grepKing7778Counterfeitflashdrive[Kingston]0100KingstonFlashDrive(128MB)c010KingstonFCR-HS2/ATACardReader07cbKingmaxTechnology,Inc.4100KingsunSF-620InfraredAdapter4959KingsunKS-959InfraredAdapter0015KingstonDataTravelerELITE0016KingstonDataTravelerU30998KingstonDataTraveler2.0DiskDriver0999KingstonDataTraveler2.0DiskDriver6519KingstonDataTraveler2.0USBStick653cKingstonDataTraveler2.0Stick(512M)653dKingstonDataTraveler2.0Stick(1GB)6544TransMemory-Mini/KingstonDataTraveler2.0Stick(2GB)6545KingstonDataTraveler102/2.0/HEMAFlashDrive2GB/PNYAttache4GBStick0951KingstonTechnology0d8aKingJimCo.,Ltd00a3SmartKingPROUninterruptiblePowerSupply(HIDPDC)0e56KingstonTechnologyCompany,Inc.0f8eKingnetTechnologyCo.,Ltd13feKingstonTechnologyCompanyInc.1f00KingstonDataTraveler/PatriotXporter1687KingmaxDigitalInc.16dfKingBillionElectronicsCo.,Ltd.2149EntropyKingRandomNumberGenerator
lsusb -v查看系统中USB设备的详细信息
lsusb-v7. lshw查看所有硬件摘要信息
下面命令可以查看所有硬件摘要信息,并输出成一个html文件,把此html文件导出到电脑上,直接打开,可以清楚的看到硬件信息:
lshw-html>/hardware.html8. lsscsi查看SCSI控制器设备的信息
可以看到SCSI信息和所有虚拟磁盘以及光驱的信息,如果没有硬件SCSI控制器,那就不会返回信息:
root@ubuntu:/home/peng#lsscsi[2:0:0:0]diskVMware,VMwareVirtualS1.0/dev/sda[4:0:0:0]cd/dvdNECVMWarVMwareSATACD011.00/dev/sr0
插入一个U盘后再查看:
root@ubuntu:/home/peng#lsscsi[2:0:0:0]diskVMware,VMwareVirtualS1.0/dev/sda[4:0:0:0]cd/dvdNECVMWarVMwareSATACD011.00/dev/sr0[33:0:0:0]diskKingstonDataTravelerG21.00/dev/sdb
可以看到U盘为Kingston。
9. 查看bios信息root@ubuntu:/home/peng#dmidecode-tbios#dmidecode3.0GettingSMBIOSdatafromsysfs.SMBIOS2.7present.Handle0x0000,DMItype0,24bytesBIOSInformationVendor:PhoenixTechnologiesLTDVersion:6.00ReleaseDate:07/29/2019Address:0xEA480RuntimeSize:88960bytesROMSize:64kBCharacteristics:ISAissupportedPCIissupportedPCCard(PCMCIA)issupportedPNPissupportedAPMissupportedBIOSisupgradeableBIOSshadowingisallowedESCDsupportisavailableBootfromCDissupportedSelectablebootissupportedEDDissupportedPrintscreenserviceissupported(int5h)8042keyboardservicesaresupported(int9h)Serialservicesaresupported(int14h)Printerservicesaresupported(int17h)CGA/monovideoservicesaresupported(int10h)ACPIissupportedSmartbatteryissupportedBIOSbootspecificationissupportedFunctionkey-initiatednetworkbootissupportedTargetedcontentdistributionissupportedBIOSRevision:4.6FirmwareRevision:0.0
dmidecode以一种可读的方式dump出机器的DMI(Desktop Management Interface)信息。这些信息包括了硬件以及BIOS,既可以得到当前的配置,也可以得到系统支持的最大配置,比如说支持的最大内存数等。
如果要查看所有有用信息
dmidecode-q
里面包含了很多硬件信息。
– EOF –
1、网络状态检测的利器:ss 命令
2、再也不用担心 SSH 断开了:tmux 命令
3、Sysstat:开源免费的 Linux 系统的监控工具
看完本文有收获?请分享给更多人