Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Linux to query OS, CPU, memory and hard disk information

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use Linux to query OS, CPU, memory, hard disk information", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use Linux to query OS, CPU, memory, hard disk information"!

one。 Preface

When we take over one or more servers, first of all, we need to have some understanding of the basic configuration of the server, so that we can prescribe the right medicine for the future software deployment, the system operation and maintenance will get twice the result with half the effort.

two。 About basic server configuration

Query the basic configuration of the server generally query the operating system, CPU, memory, hard disk, the following one by one to explain.

2.1 query for basic configuration of the operating system

View operating system version

# cat / etc/redhat-release this command is mainly used to check the version number of the operating system issued by Red Hat [root@node5 ~] # cat / etc/redhat-release CentOS Linux release 7.4.1708 (Core) # cat / etc/issue this command applies to most linux distributions [root@node5 ~] # cat / etc/issueSKernel r on an m

View the operating system kernel version

[root@node5] # uname-r3.10.0-693.el7.x86_64

View operating system details

[root@node5 ~] # uname-aLinux node5 3.10.0-693.el7.x86_64 # 1 SMP Tue Aug 22 21:09:27 UTC 2017 x86 "64 GNU/Linux# you can see from the above output that the hostname of the server is node5,linux kernel version 3.10.0-693.el7.x86_64 CPU is x86 architecture # this command can see more information [root@node5 ~] # more / etc/*release: / etc/centos-release:CentOS Linux release 7.4.1708 (Core): / etc/os-release:NAME= "CentOS Linux" VERSION= "7 (Core) ) "ID=" centos "ID_LIKE=" rhel fedora "VERSION_ID=" 7 "PRETTY_NAME=" CentOS Linux 7 (Core) "ANSI_COLOR=" 0 31 "CPE_NAME=" cpe:/o:centos:centos:7 "HOME_URL=" https://www.centos.org/"BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"CENTOS_MANTISBT_PROJECT_VERSION="7"REDHAT_SUPPORT_PRODUCT="centos"REDHAT_SUPPORT_PRODUCT_VERSION="7"::::::::::::::/etc/redhat-release::::::::::::: : CentOS Linux release 7.4.1708 (Core): / etc/system-release:CentOS Linux release 7.4.1708 (Core)

2.2 CPU basic configuration query

Noun interpretation

Check the physical number of CPU

[root@node5 ~] # grep 'physical id' / proc/cpuinfo | sort-u | wc-L1

View the number of CPU cores

[root@node5 ~] # grep 'core id' / proc/cpuinfo | sort-u | wc-L4

View number of CPU threads

# logical cpu number: in general, the number of logical cpu= physical CPU × the number of cores per core. If it is not equal, it means that the server's CPU supports hyper-threading technology (HT: to put it simply, it enables one kernel in the processor # to function as two cores in the operating system. In this way, the execution resources available to the operating system are doubled, and the overall performance of the system is greatly improved. In this case, the number of physical CPU of cpu= in logic # series x2) [root@node5 ~] # cat / proc/cpuinfo | grep "processor" | wc-L4 [root@node5 ~] # grep 'processor' / proc/cpuinfo | sort-u | wc-L4

View CPU model

[root@node5 ~] # cat / proc/cpuinfo | grep name | sort | uniqmodel name: Intel (R) Core (TM) i7-8550U CPU @ 1.80GHz [root@node5 ~] # dmidecode-s processor-version | uniq # deduplicates Intel (R) Core (TM) i7-8550U CPU @ 1.80GHz using uniq

View the details of CPU

# CPU has several cores Several repetitive messages [root@node5 ~] # cat / proc/cpuinfoprocessor: 0vendor_id: GenuineIntelcpu family: 142model name: Intel (R) Core (TM) i7-8550U CPU @ 1.80GHzstepping: 10microcode: 0x96cpu MHz: 2000.921cache size: 8192 KBphysical id: 0siblings: 4core id: 0cpu cores: 4apicid: 0initial apicid: 0fpu: yesfpu_exception: yescpuid level: 22wp: yesflags: 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 vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec aratbogomips: 4002.00clflush size: 64cache_alignment: 64address sizes: 43 bits physical 48 bits virtualpower management:

View the details of CPU

[root@node5 ~] # lscpuArchitecture: x86_64CPU op-mode (s): 32-bit 64-bitByte Order: Little EndianCPU (s): 4On-line CPU (s) list: 0-3Thread (s) per core: 1Core (s) per socket: 4Socket (s): 1NUMA node (s): 1Vendor ID: GenuineIntelCPU family: 6Model: 142Model name: Intel (R) Core ( TM) i7-8550U CPU @ 1.80GHzStepping: 10CPU MHz: 2000.921BogoMIPS: 4002.00Virtualization: VT-xHypervisor vendor: VMwareVirtualization type: fullL1d cache: 32KL1i cache: 32KL2 cache: 256KL3 cache: 8192KNUMA node0 CPU (s): 0-3Flags: 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 vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat

Summary of CPU configuration

From the above query, we can know that the server is a 4-core CPU, the CPU model is Intel (R) Core (TM) i7-8550U CPU @ 1.80GHz, and the CPU is not hyper-threaded.

2.3 basic memory configuration query

Noun interpretation

Query server memory

[root@node5] # free-m total used free shared buff/cache availableMem: 3941 286 3446 19208 3407Swap: 2047 0204 linux Note # the idea of memory management mechanism includes (dare not say that is) memory utilization maximization. The kernel requests the remaining memory as cached, while cached does not fall into the category of free. When the system runs # lines for a long time, you will find that the cached is very large, especially for systems with frequent file read and write operations. Intuitively, at this time, the memory of free will be very small, but it does not mean that the memory used by # # is small. When a program needs to apply for larger memory, if the memory of free is not enough, the kernel will reclaim part of the memory of cached and redistribute the recovered memory to the application. So # for linux systems, the memory available for allocation is not only free memory, but also cached memory (which actually includes buffers). # for operating systems: # MemFree=total-used#MemUsed = MemTotal-MemFree# for applications: # MemFree=buffers+cached+free

Query memory every 3 seconds

[root@node5] # free-s 3 total used free shared buff/cache availableMem: 4036316 361144 3458272 19536 216900 3419776Swap: 2097148 0 2097148 total used free shared buff/cache availableMem: 4036316 361144 3458272 19536 216900 3419776Swap: 2097148 02097148 total Used free shared buff/cache availableMem: 4036316 361144 3458272 19536 216900 3419776Swap: 2097148 0 2097148

2.4 query for basic configuration of hard disk

Query the overall disk usage

[root@node5 ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 17G 4.1G 13G 24% / devtmpfs 2.0G 02.0G 0% / devtmpfs 2.0G 8.0K 2.0G 1% / dev/shmtmpfs 2.0G 8.7M 2.0G 1% / runtmpfs 2.0G 02.0G 0% / sys/fs/cgroup/dev/sda1 1014M 125m 890M 13% / boottmpfs 395M 0395M 0% / run/user/0# Command extension # df-a shows the usage of all file systems # df-I displays inode information # df-k byte display block occupancy # df-T shows the type of file system

Query the disk usage of a directory

# Command extension # du-s specified directory size summary # du-h with unit of measurement # du-a contains file # du-max-depth=1 subdirectory depth # du-c list details at the same time Increase the total value [root@node5 ~] # du-sh / home/1.7G / home/ [root@node5 ~] # du-ach-- max-depth=2 / home/4.0K / home/www/.bash_logout4.0K / home/www/.bash_profile4.0K / home/www/.bashrc4.0K / home/www/web16K / home/www4.0K / home/nginx/.bash_logout4.0K / home/nginx/.bash_profile4.0K / Home/nginx/.bashrc12K / home/nginx4.0K / home/esnode/.bash_logout4.0K / home/esnode/.bash_profile4.0K / home/esnode/.bashrc4.0K / home/esnode/.oracle_jre_usage4.3M / home/esnode/elasticsearch-analysis-ik-6.2.2.zip80M / home/esnode/kibana-6.2.2-linux-x86_64.tar.gz300M / home/esnode/x-pack-6.2.2.zip28M / home/esnode/elasticsearch-6.2.2.tar.gz4.0K / home/esnode/.bash_history294M / home/esnode/elasticsearch-6.2.24.0K / home/esnode/.ssh4.0K / home/esnode/x-pack generated secret key .txt1014M / home/esnode/kibana-6.2.2-linux-x86_648.0K / home/esnode/.viminfo1.7G / home/esnode1.7G / home/1.7G total

View directory structure

# tree command is not installed by default You need to manually install [root@node5 ~] # yum-y install tree#-L to specify directory depth [root@node5 ~] # tree-L 2 / home//home/ ├── esnode │ ├── elasticsearch-6.2.2 │ elasticsearch-6.2.2.tar.gz │ ├── elasticsearch-analysis-ik-6.2.2.zip │ ├── kibana-6.2.2-linux-x86_64 │ ├── kibana-6.2.2-linux-x86_64.tar.gz │ ├── x-pack-6.2.2.zip │ └── x-pack347224237346210220347232204347247230351222245.txt ├── nginx └── www └── web6 directories 5 files

Displays all available block device information in a tree format

[root@node5 ~] # lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk ├─ sda1 8:1 0 1G 0 part / boot └─ sda2 8:2 0 19G 0 part ├─ centos-root 253 sda2 0 017G 0 lvm / └─ centos-swap 253 Switzerland 1 0 2G 0 lvm [SWAP] sdb 8:16 0 1G 0 disk └─ sdb1 8:17 0 200M 0 part sr0 11:0 1 1024M 0 rom# comment # NAME-- name of the device # MAJ:MIN-- each device in the Linux operating system is represented by a file For block (disk) devices, the primary and secondary device numbers are used to describe the device. # RM-removable device. If this is a removable device, 1 will be displayed, otherwise 0 will be displayed. # TYPE-- Type of device # MOUNTPOINT-- location where the device is mounted # RO-- for read-only file systems, 1 is displayed, otherwise 0 is displayed. # SIZE-the capacity of the device

List all available devices, universal unique identification number (UUID), file system type, and volume label

[root@node5] # blkid/dev/sda1: UUID= "6503b4ad-2975-4152-a824-feb7bea1b622" TYPE= "xfs" / dev/sda2: UUID= "nqZ4uJ-ksnN-KzYS-N42b-00m3-Ohc2-BJXunP" TYPE= "LVM2_member" / dev/sdb1: UUID= "94396e17-4821-4957-aa76-d41f33958ff5" TYPE= "xfs" / dev/mapper/centos-root: UUID= "c1d38b37-821d-48e7-8727-3937ccc657a4" TYPE= "xfs" / dev/mapper/centos-swap: UUID= "c2fcaf11-42d8 -4e4c-bf9e-6464f0777198 "TYPE=" swap Thank you for your reading The above is the content of "how to use Linux to query OS, CPU, memory, hard disk information". After the study of this article, I believe you have a deeper understanding of how to use Linux to query OS, CPU, memory, hard disk information. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report