在Linux下,我们经常需要查看系统的硬件信息,这里我罗列了查看系统硬件信息的实用命令,并做了分类,实例解说。
执行环境:ubuntu16.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.....
内存最大值是491520MB。
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/Solaris
4.网卡
查看网卡硬件信息
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#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.....0
5.pci
查看pci信息,即主板所有硬件槽信息。
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.....1
由上述的输出可以看到,我的电脑上共有3个PCI总线(0号,1号,2号)。在单个系统上,插入多个总线是通过桥(bridge)来完成的,桥是一种用来连接总线的特殊PCI外设。所以,PCI系统的整体布局组织为树型,我们可以通过上面的lspci输出,来画出我的电脑上的PCI系统的树型结构:
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
由上图可以得出,我的电脑上共有8个PCI设备,其中0号总线上(主桥)上连有4个,1号总线上连有1个,2号总线上连有3个。00:1f是一个连有5个功能的多功能板卡。
如果要更详细的信息:
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.....3
如果要看设备树:lscpi-t
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.....4
6.usb
查看usb信息
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.....5
lsusb-t查看系统中的USB拓扑,类似cat/sys/kernel/debug/usb/devices
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.....6
/var/lib/usbutils/usb.ids还保存了很多设备商的VID信息
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.....7
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.....8查看系统中USB设备的详细信息
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.....8
7.lshw查看所有硬件摘要信息
下面命令可以查看所有硬件摘要信息,并输出成一个html文件,把此html文件导出到电脑上,直接打开,可以清楚的看到硬件信息:
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.....9
8.lsscsi查看SCSI控制器设备的信息
可以看到SCSI信息和所有虚拟磁盘以及光驱的信息,如果没有硬件SCSI控制器,那就不会返回信息:
root@ubuntu:/home/peng#free-mtotalusedfreesharedbuff/cacheavailableMem:1970702315139521025Swap:974209540
插入一个U盘后再查看:
root@ubuntu:/home/peng#free-mtotalusedfreesharedbuff/cacheavailableMem:1970702315139521025Swap:974209540[33:0:0:0]diskKingstonDataTravelerG21.00/dev/sdb
可以看到U盘为Kingston。
9.查看bios信息
root@ubuntu:/home/peng#free-mtotalusedfreesharedbuff/cacheavailableMem:1970702315139521025Swap:974209542
dmidecode以一种可读的方式dump出机器的DMI(DesktopManagementInterface)信息。这些信息包括了硬件以及BIOS,既可以得到当前的配置,也可以得到系统支持的最大配置,比如说支持的最大内存数等。
如果要查看所有有用的信息
root@ubuntu:/home/peng#free-mtotalusedfreesharedbuff/cacheavailableMem:1970702315139521025Swap:974209543
里面包含了很多硬件信息。