Linux环境获取系统基本信息
查找Linux Kernel版本
root@server:~# uname -a
Linux server 4.4.0-157-generic #185-Ubuntu SMP Tue Jul 23 09:17:01 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
查看当前系统的发行版名称和版本
root@server:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
当然你同样可以使用 lsb_release
命令来查看上述信息
root@server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
更多的使用详情,请参看 man lsb_release
查找 CPU 32位/64位?
getconf
是一个获取系统配置信息的工具.要获取CPU是32位还是64位,可以使用它来完成.
root@server:~# getconf LONG_BIT
64
从这里可以看到当前CPU是64位的,不过市面上目前的64位的CPU大多都兼容32位指令集,可以通过lscpu命令进一步验证
root@server:~# 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: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Stepping: 10
CPU MHz: 1992.002
BogoMIPS: 3984.00
Hypervisor vendor: KVM
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 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase avx2 invpcid rdseed clflushopt md_clear flush_l1d
更多CPU的信息,还可以通过查看内核生成的 proc
下的 cpuinfo
信息.
root@server:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
cpu MHz : 1992.002
cache size : 8192 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4
_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase avx2 invpcid rdseed clflushopt md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds
bogomips : 3984.00
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
......
查看系统内存信息
系统的基本信息在 proc
的内容下都有对应的文本描述, 内存的信息在 /proc/meminfo
root@server:~# cat /proc/meminfo
MemTotal: 4045996 kB
MemFree: 3076076 kB
MemAvailable: 3603832 kB
Buffers: 117928 kB
Cached: 571992 kB
SwapCached: 0 kB
Active: 470976 kB
Inactive: 313008 kB
Active(anon): 97128 kB
Inactive(anon): 5224 kB
Active(file): 373848 kB
Inactive(file): 307784 kB
Unevictable: 3652 kB
Mlocked: 3652 kB
SwapTotal: 998396 kB
SwapFree: 998396 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 97792 kB
Mapped: 50300 kB
Shmem: 5868 kB
Slab: 130188 kB
SReclaimable: 98492 kB
SUnreclaim: 31696 kB
KernelStack: 3872 kB
PageTables: 5272 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 3021392 kB
Committed_AS: 783016 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 83904 kB
DirectMap2M: 4110336 kB
查看GPU的信息
lspci
用于查看机器的 pci
的设备信息, GPU设备作为 Video
设备呈现
lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:02.0 VGA compatible controller: VMware SVGA II Adapter
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01)
00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB
00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:08.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:0b.0 USB controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) USB2 EHCI Controller
00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)
查看磁盘的挂载和使用情况
root@server:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 5.8M 390M 2% /run
/dev/sda1 147G 5.7G 134G 5% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 396M 0 396M 0% /run/user/0
查看 USB 设备
lsusb
命令用于查看系统集成的USB设备
root@server:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
除了使用 lsusb
, 还有部分设备, 可以通过 xinput
命令来查看
root@server:~# xinput
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech G102 Prodigy Gaming Mouse id=10 [slave pointer (2)]
⎜ ↳ Logitech G102 Prodigy Gaming Mouse id=11 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=14 [slave pointer (2)]
⎜ ↳ TPPS/2 IBM TrackPoint id=15 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Video Bus id=8 [slave keyboard (3)]
↳ Sleep Button id=9 [slave keyboard (3)]
↳ Integrated Camera: Integrated C id=12 [slave keyboard (3)]
↳ AT Raw Set 2 keyboard id=13 [slave keyboard (3)]
↳ ThinkPad Extra Buttons id=16 [slave keyboard (3)]
↳ Logitech G102 Prodigy Gaming Mouse id=17 [slave keyboard (3)]