Linux系统下查看CPU、内存、磁盘、网卡等信息方法

一、查看CPU信息



1、 查看物理CPU的个数

[root@centos7 data]# cat /proc/cpuinfo |grep "physical id"|sort|uniq|wc -l
2

2、 查看CPU是几核

[root@centos7 data]# cat /proc/cpuinfo |grep "cores"|uniq
cpu cores   : 2

3、 查看逻辑CPU的个数

[root@centos7 data]# cat /proc/cpuinfo |grep "processor"|wc -l
4

4、 查看CPU的主频

[root@centos7 data]# cat /proc/cpuinfo |grep "GHz"|uniq
model name  : Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz

5、 同时查看逻辑CPU个数和CPU核数

[root@centos7 data]# cat /proc/cpuinfo |grep name |cut -f2 -d:|uniq -c
4  Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz

6、 使用lscpu命令,可以一次查看所有信息

[root@centos7 data]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Stepping:              9
CPU MHz:               4200.007
BogoMIPS:              8400.01
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0-3
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec ibpb ibrs stibp arat spec_ctrl intel_stibp arch_capabilities

二、查看内存信息

1、[root@centos7 data]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3773         799        2245          14         728        2673
Swap:          4095           0        4095
2、 [root@centos7 data]# cat /proc/meminfo 
MemTotal:        3863568 kB
MemFree:         2299312 kB
MemAvailable:    2737396 kB
Buffers:            2120 kB
Cached:           635396 kB
SwapCached:            0 kB
Active:           912192 kB
Inactive:         379512 kB
Active(anon):     655460 kB
Inactive(anon):    13852 kB
Active(file):     256732 kB
Inactive(file):   365660 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4194300 kB
SwapFree:        4194300 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        654208 kB
Mapped:           130076 kB
Shmem:             15124 kB
Slab:             108236 kB
SReclaimable:      40620 kB
SUnreclaim:        67616 kB
KernelStack:       10352 kB
PageTables:        40580 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6126084 kB
Committed_AS:    3977456 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      186988 kB
VmallocChunk:   34359310332 kB
HardwareCorrupted:     0 kB
AnonHugePages:    268288 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      126784 kB
DirectMap2M:     4067328 kB
DirectMap1G:     2097152 kB


三、 查看磁盘信息
1、 查看磁盘挂载信息(常用)

[root@centos7 data]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0  199G  0 part 
  ├─centos-root 253:0    0  145G  0 lvm  /
  ├─centos-swap 253:1    0    4G  0 lvm  [SWAP]
  └─centos-data 253:2    0   50G  0 lvm  /data
sr0              11:0    1 1024M  0 rom

2、 查看磁盘具体信息

[root@centos7 data]# fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a26b6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

Disk /dev/mapper/centos-root: 155.7 GB, 155684175872 bytes, 304070656 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos-data: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


四、 查看网卡信息

[root@centos7 data]# mii-tool  ens33            #ens33表示网卡名称
ens33: negotiated 1000baseT-FD flow-control, link ok            #虚拟机环境是千兆 ,link ok 表示正在连接当中
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 好的,下面是一个可以打印出 Linux 服务器的 CPU内存磁盘网卡信息的 shell 脚本的示例: ``` #!/bin/bash # 打印 CPU 信息 echo "CPU 信息:" cat /proc/cpuinfo | grep "model name" # 打印内存信息 echo "内存信息:" free -h # 打印磁盘信息 echo "磁盘信息:" df -h # 打印网卡信息 echo "网卡信息:" ip a ``` 这个脚本使用了几个 Linux 系统内置的命令来获取信息: - `cat /proc/cpuinfo`: 打印 CPU 的详细信息。 - `grep "model name"`: 在输出中搜索 "model name" 字符串。 - `free -h`: 打印内存的使用情况。 - `df -h`: 打印磁盘的使用情况。 - `ip a`: 打印网卡信息。 请注意,要运行这个脚本,需要使用以下命令: ``` chmod +x script.sh # 修改脚本的权限 ./script.sh # 运行脚本 ``` 希望这些信息能够帮到你。 ### 回答2: 要实现这个功能,可以使用shell脚本来获取不同硬件信息。以下是一个可以打印出Linux服务器CPU内存磁盘网卡等详情的示例脚本: ```bash #!/bin/bash # 获取CPU信息 cpu_info=$(cat /proc/cpuinfo | grep "model name" | head -n 1 | awk -F: '{print $2}') echo "CPU: $cpu_info" # 获取内存信息 mem_info=$(free -h | awk 'NR==2{print "Total: " $2, "Used: " $3}') echo "Memory: $mem_info" # 获取磁盘信息 disk_info=$(df -h | awk 'NR==2{print "Total: " $2, "Used: " $3, "Free: " $4}') echo "Disk: $disk_info" # 获取网卡信息 nic_info=$(ifconfig | grep "eth" | awk '{print $1}') echo "Network Interface: $nic_info" ``` 上述脚本中,首先使用`cat /proc/cpuinfo`命令获取CPU信息,然后使用`grep`和`awk`命令提取出CPU型号,存储在变量`cpu_info`中。 接下来使用`free -h`命令获取内存信息,`awk`命令过滤出总内存和已使用内存,存储在变量`mem_info`中。 然后使用`df -h`命令获取磁盘信息,`awk`命令过滤出总磁盘空间、已使用空间和剩余空间,存储在变量`disk_info`中。 最后使用`ifconfig`命令获取网卡信息,`grep`和`awk`命令过滤出以"eth"开头的网卡名称,存储在变量`nic_info`中。 最后,使用`echo`命令分别打印出CPU内存磁盘网卡信息。 可以执行该脚本来获取服务器的硬件信息,`./script.sh`(假设脚本文件名为`script.sh`),输出结果会显示服务器的CPU型号、内存使用情况、磁盘信息网卡名称。 ### 回答3: 编写一个Shell脚本来获取Linux服务器的CPU内存磁盘网卡等详细信息。可以使用以下代码: ```shell #!/bin/bash # 获取CPU信息 cpu_info=$(cat /proc/cpuinfo | grep "model name" | awk -F ': ' '{print $2}') # 获取内存信息 mem_info=$(free -h | awk '/Mem/ {print $2}') # 获取磁盘信息 disk_info=$(df -h) # 获取网卡信息 interface_info=$(ifconfig -a) # 打印详细信息 echo "CPU信息:" echo "$cpu_info" echo "------------------------" echo "内存信息:" echo "$mem_info" echo "------------------------" echo "磁盘信息:" echo "$disk_info" echo "------------------------" echo "网卡信息:" echo "$interface_info" ``` 这个脚本使用一系列Linux命令来获取各种信息。首先,使用`cat`和`grep`命令获取CPU的型号信息。然后,使用`free`命令获取内存信息,并使用`awk`命令从输出中提取所需的数据。接下来,使用`df`命令获取磁盘信息,使用`ifconfig`命令获取网卡信息。最后,通过`echo`命令打印详细信息。 要运行此脚本,只需在命令行中执行`bash 脚本名.sh`,然后将会输出Linux服务器的CPU内存磁盘网卡的详细信息

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值