参考API网址:Linux 命令大全
Linux资源配置
查看
汇总
查看系统配置,汇总信息CPU、内存、硬盘、网络等等:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
sudo lshw | grep less
输出:
olimi-pc
description: Computer
width: 64 bits
capabilities: smp vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 1
size: 12GiB
*-cpu
product: Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
vendor: Intel Corp.
physical id: 2
bus info: cpu@0
width: 64 bits
capabilities: fpu fpu_exception wp 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 x86-64 constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti ssbd ibrs ibpb stibp fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves md_clear flush_l1d arch_capabilities
*-display
description: 3D controller
product: Microsoft Corporation
vendor: Microsoft Corporation
physical id: 0
bus info: pci@cd21:00:00.0
version: 00
width: 32 bits
clock: 33MHz
capabilities: bus_master cap_list
configuration: driver=dxgkrnl latency=0
resources: irq:0
*-scsi
physical id: 3
logical name: scsi0
*-disk:0
description: EXT4 volume
product: Virtual Disk
vendor: Linux
physical id: 0.0.0
bus info: scsi@0:0.0.0
logical name: /dev/sda
version: 1.0
serial: 3255683f-53a2-4fdf-91cf-b4c1041e2a62
size: 256GiB
capabilities: journaled extended_attributes large_files huge_files dir_nlink recover 64bit extents ext4 ext2 initialized
configuration: ansiversion=5 created=2019-04-11 00:35:05 filesystem=ext4 lastmountpoint=/swap logicalsectorsize=512 modified=2022-04-10 11:06:59 mounted=2022-04-10 11:06:59 sectorsize=4096 state=clean
*-disk:1
description: EXT4 volume
product: Virtual Disk
vendor: Linux
physical id: 0.0.1
bus info: scsi@0:0.0.1
logical name: /dev/sdb
logical name: /
version: 1.0
serial: 3255683f-53a2-4fdf-91cf-b4c1041e2a62
size: 256GiB
capabilities: journaled extended_attributes large_files huge_files dir_nlink recover 64bit extents ext4 ext2 initialized
configuration: ansiversion=5 created=2019-04-11 00:35:05 filesystem=ext4 lastmountpoint=/distros logicalsectorsize=512 modified=2022-04-10 11:07:01 mount.fstype=ext4 mount.options=rw,relatime,discard,errors=remount-ro,data=ordered mounted=2022-04-10 11:07:01 sectorsize=4096 state=mounted
*-network:0 DISABLED
description: Ethernet interface
physical id: 1
logical name: bond0
serial: 6e:14:5b:8f:54:0e
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=bonding driverversion=5.10.16.3-microsoft-standard-WS firmware=2 link=no master=yes multicast=yes
*-network:1 DISABLED
description: Ethernet interface
physical id: 2
logical name: dummy0
serial: ea:b4:ca:e1:ed:db
capabilities: ethernet physical
configuration: broadcast=yes driver=dummy driverversion=5.10.16.3-microsoft-standard-WS
*-network:2
description: Ethernet interface
physical id: 3
logical name: eth0
serial: 00:15:5d:08:47:9a
size: 10Gbit/s
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=hv_netvsc driverversion=5.10.16.3-microsoft-standard-WS duplex=full firmware=N/A ip=192.168.33.43 link=yes multicast=yes speed=10Gbit/s
信息显示太多,可以单独只输出某个部分,比如:
1
2
3
4
5
6
7
8
9
10
11
12
$ sudo lshw -c cpu -c memory
*-memory
description: System memory
physical id: 1
size: 12GiB
*-cpu
product: Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
vendor: Intel Corp.
physical id: 2
bus info: cpu@0
width: 64 bits
capabilities: fpu fpu_exception wp 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 x86-64 constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti ssbd ibrs ibpb stibp fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves md_clear flush_l1d arch_capabilities
CPU
单独的一些查看,CPU(静态信息):
1
cat /proc/cpuinfo | grep model\ name
内存
内存Memory(动态信息):
1
2
3
4
$ free -mh
total used free shared buff/cache available
Mem: 12G 263M 12G 64K 74M 11G
Swap: 4.0G 241M 3.8G
free - Display amount of free and used memory in the system
硬盘
查看硬盘信息(动态):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sdb 251G 8.7G 230G 4% /
tmpfs 6.2G 0 6.2G 0% /mnt/wsl
tools 118G 61G 57G 52% /init
none 6.2G 0 6.2G 0% /dev
none 6.2G 8.0K 6.2G 1% /run
none 6.2G 0 6.2G 0% /run/lock
none 6.2G 0 6.2G 0% /run/shm
none 6.2G 0 6.2G 0% /run/user
tmpfs 6.2G 0 6.2G 0% /sys/fs/cgroup
drivers 118G 61G 57G 52% /usr/lib/wsl/drivers
lib 118G 61G 57G 52% /usr/lib/wsl/lib
# 我这是WSL
df - report file system disk space usage
显卡
显卡:
1
2
3
$ lspci
cd21:00:00.0 3D controller: Microsoft Corporation Device 008e
# 我这还是WSL
设置
虚拟内存
下面是Linux上设置虚拟内存的方式(在Linux中需要做的是设置交换文件,即swap)
执行“sudo swapon -s”命令,查看是否已经存在swap file
如果第一步存在swapfile则需要先禁用
sudo swapoff /swapfile
- 修改swap 空间的大小为8G
1
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
- 设置文件为“swap file”类型
sudo mkswap /swapfile
- 启用swapfile
sudo swapon /swapfile
链接:https://www.jianshu.com/p/e656bead51ee
注意(坑):以上操作必须一起完成!!否则在swapoff了原本的swapfile之后会导致无法开机。因为系统没办法挂载原本的swapfile。如果中间没完成,记得重新把/swapfile挂载回去!
然后如果是使用WSL,配置方式:
添加文件.wslconfig
,文件路径为 C:\Users\<UserName>\.wslconfig
.文件内容:
1
2
3
4
5
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=40GB
注意如果是动态修改不能更改swap位置,否则不能生效(这里跟上面linux同理,不能更改系统原本的swapfile文件,否则会导致系统损坏,或者不起效)。要更改swap位置,必须重装或新安装时就指定。