跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

Linux查看系统硬件信息的九个命令实例详解

在Linux下,我们要遇到需要查看系统的硬件信息, 这里我罗列了查看系统硬件信息的实用命令,并做了分类,实例解说。

执行环境:ubuntu 16.04 1. cpu lscpu命令,查看的是cpu的统计信息. 123456789101112131415161718192021222324root@ubuntu:/home/peng/# lscpuArchitecture:          x86_64            #cpu架构CPU op-mode(s):        32-bit, 64-bitByte Order:            Little Endian     #小尾序CPU(s):                1                 #总共有1核   On-line CPU(s) list:   0Thread(s) per core:    1                 #每个cpu核,只能支持一个线程,即不支持超线程 Core(s) per socket:    1Socket(s):             1NUMA node(s):          1Vendor ID:             GenuineIntel     #cpu产商 intelCPU family:            6Model:                 158Model name:            Intel(R) Core(TM) i5-7500 CPU @ 3.40GHzStepping:              9CPU MHz:               3408.070BogoMIPS:              6816.14Hypervisor vendor:     VMwareVirtualization type:   full             #支持cpu虚拟化技术L1d cache:             32KL1i cache:             32KL2 cache:              256KL3 cache:              6144KNUMA node0 CPU(s):     0 查看/proc/cpuinfo,可以知道每个cpu信息,如每个CPU的型号,主频等。

123456789101112131415161718192021root@ubuntu:/home/peng# cat /proc/cpuinfoprocessor   : 0vendor_id   : GenuineIntelcpu family  : 6model       : 158model name  : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHzstepping    : 9microcode   : 0x48cpu MHz     : 3408.070cache size  : 6144 KBphysical id: 0siblings    : 1core id: 0cpu cores   : 1apicid      : 0initial apicid  : 0fpu     : yesfpu_exception   : yescpuid level : 22wp      : yes..... 2. 内存 概要查看内存情况 1234root@ubuntu:/home/peng# free -m              total        used        freeshared  buff/cacheavailableMem:           1970         702         315          13         952        1025Swap:           974          20         954 这里的单位是MB,总共的内存是1970MB。

查看内存详细使用 12345678910111213141516root@ubuntu:/home/peng# cat /proc/meminfo MemTotal:        2017516 kBMemFree:          242020 kBMemAvailable:    1003240 kBBuffers:          104192 kBCached:           699824 kBSwapCached:         1832 kBActive:           696320 kBInactive:         639924 kBActive(anon):     236412 kBInactive(anon):   301996 kBActive(file):     459908 kBInactive(file):   337928 kBUnevictable:          48 kBMlocked:              48 kB..... 查看内存硬件信息 12345678910111213141516171819202122232425root@ubuntu:/home/peng# dmidecode -t memory# dmidecode 3.0                                                                                                                                                                                 Getting SMBIOS data from sysfs.SMBIOS 2.7 present. Handle 0x0084, DMI type5, 46 bytesMemory Controller Information    Error Detecting Method: None    Error Correcting Capabilities:         None    Supported Interleave: One-way Interleave    Current Interleave: One-way Interleave    Maximum Memory Module Size: 32768 MB    Maximum Total Memory Size: 491520 MB    Supported Speeds:        70 ns        60 ns    Supported Memory Types:        FPM        EDO        DIMM        SDRAM    Memory Module Voltage: 3.3 V    Associated Memory Slots: 15..... 内存最大值是 491520 MB。

3. 磁盘 查看硬盘和分区分布 1234567root@ubuntu:/home/peng# lsblkNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsr0     11:0    1 1024M  0 rom  sda      8:0    0  500G  0 disk ├─sda2   8:2    0    1K  0 part ├─sda5   8:5    0  975M  0 part [SWAP]└─sda1   8:1    0  499G  0 part / 查看硬盘和分区的详细信息 123456789101112root@ubuntu:/home/peng# fdisk -lDisk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x9c674a44 Device     Boot      Start        End    Sectors  Size Id Type/dev/sda1*          2048 1046575103 1046573056  499G 83 Linux/dev/sda21046577150 1048573951    1996802  975M  5 Extended/dev/sda51046577152 1048573951    1996800  975M 82 Linux swap / Solaris 4. 网卡 查看网卡硬件信息 12root@ubuntu:/home/peng# lspci | grep -i 'eth'02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) 查看系统的所有网络接口 123456789101112131415161718root@ubuntu:/home/peng# ifconfig -aens33     Link encap:Ethernet  HWaddr 00:0c:29:bb:bd:40            inet addr:192.168.0.117  Bcast:192.168.0.255  Mask:255.255.255.0          inet6 addr: fe80::76fa:5548:3da0:2ef/64Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:174629 errors:0 dropped:0 overruns:0 frame:0          TX packets:105285 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:237519396 (237.5 MB)  TX bytes:9592767 (9.5 MB) lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:854 errors:0 dropped:0 overruns:0 frame:0          TX packets:854 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:60894 (60.8 KB)  TX bytes:60894 (60.8 KB) 或者是 12345root@ubuntu:/home/peng# ip link show1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000    link/loopback00:00:00:00:00:00 brd 00:00:00:00:00:002: ens33: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000    link/ether00:0c:29:bb:bd:40 brd ff:ff:ff:ff:ff:ff 或者

如果要查看某个网络接口的详细信息,例如ens33的详细参数和指标 【有的ubuntu网口是eth0】 12345678910111213141516171819202122232425root@ubuntu:/home/peng# ethtool ens33Settings forens33:    Supported ports: [ TP ]    Supported link modes:   10baseT/Half10baseT/Full                            100baseT/Half100baseT/Full#支持千兆半双工,全双工模式                            1000baseT/Full    Supported pause frame use: No    Supports auto-negotiation: Yes #默认使用自适应模式    Advertised link modes:  10baseT/Half10baseT/Full                            100baseT/Half100baseT/Full                            1000baseT/Full    Advertised pause frame use: No    Advertised auto-negotiation: Yes    Speed: 1000Mb/s#网卡的速度是1000Mb    Duplex: Full    #全双工    Port: Twisted Pair    PHYAD: 0    Transceiver: internal    Auto-negotiation: on    MDI-X: off (auto)    Supports Wake-on: d    Wake-on: d    Current message level: 0x00000007 (7)                   drv probe link    Link detected: yes#表示有网线连接,和路由是通的 5. pci 查看pci信息,即主板所有硬件槽信息。

12345678910111213141516root@ubuntu:/home/peng# lspci    00:00.0 Host bridge: Intel Corporation 82845 845 (Brookdale) Chipset Host Bridge (rev 04)    00:01.0 PCI bridge: Intel Corporation 82845 845 (Brookdale) Chipset AGP Bridge(rev 04)    00:1d.0 USB Controller: Intel Corporation 82801CA/CAMUSB (Hub #1) (rev 02)    00:1d.1 USB Controller: Intel Corporation 82801CA/CAMUSB (Hub #2) (rev 02)    00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 42)    00:1f.0 ISA bridge: Intel Corporation 82801CAM ISA Bridge (LPC) (rev 02)    00:1f.1 IDE interface: Intel Corporation 82801CAM IDE U100 (rev 02)    00:1f.3 SMBus: Intel Corporation 82801CA/CAMSMBus Controller (rev 02)    00:1f.5 Multimedia audio controller:Intel Corporation 82801CA/CAMAC'97 Audio Controller (rev 02)    00:1f.6 Modem: Intel Corporation 82801CA/CAMAC'97 Modem Controller (rev 02)    01:00.0 VGA compatible controller: nVidia Corporation NV17 [GeForce4 420 Go](rev a3)    02:00.0 FireWire (IEEE 1394): VIA Technologies, Inc. IEEE 1394 Host Controller(rev 46)    02:01.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+(rev 10)    02:04.0 CardBus bridge: O2 Micro, Inc. OZ6933 Cardbus Controller (rev 01)    02:04.1 CardBus bridge: O2 Micro, Inc. OZ6933 Cardbus Controller (rev 01) 由上述的 输出可以看到,我的电脑上共有3个PCI总线(0号,1号,2号)。

在单个系统上,插入多个总线是通过桥(bridge)来完成的,桥是一种用来连接总线 的特殊PCI外设。

所以,PCI系统的整体布局组织为树型,我们可以通过上面的lspci输出,来画出我的电脑上的PCI系统的树型结构: 1234567891011121314151617181920212200: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个功能的多功能板卡。

相关文章