ARTICLE - Cloud Servers

Ways to Check the CPU Model on CentOS 7

You can check the CPU model and core count on CentOS 7 with a single command. This article covers the /proc/cpuinfo pipeline and alternatives such as lscpu for server selection and performance assessment.

2023-04-08 cnblogs.com (CQZHUOMI)

Ways to Check the CPU Model on CentOS 7

On CentOS 7, inspecting the CPU model usually means verifying hardware, checking a VM against its plan, or recording node specs.

1. The quickest command

cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

Example output:

[root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
     40  Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz

The leading 40 is the logical CPU count. The text after the colon is the model name.

1.1 What each part does

Segment Purpose
cat /proc/cpuinfo Read the CPU data exposed by the kernel
grep name Keep only the model lines
cut -f2 -d: Split by colon and return the model field
uniq -c Merge identical lines and count occurrences

Because /proc/cpuinfo prints one block per logical CPU, the model line repeats many times. uniq -c collapses the duplicates so the number becomes useful.

1.2 When this command is enough

If you only need to confirm that the machine matches the quote or the provider plan, this command is enough. For benchmarking or capacity planning, add more fields.

2. Better alternatives

2.1 lscpu

lscpu

lscpu gives you a more readable summary of architecture, core count, thread count, model name, and cache information.

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Model name:            Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz
CPU(s):                40

2.2 Direct model lookup

cat /proc/cpuinfo | grep "model name"
---

This is useful when you only need the model string and not the count.

2.3 Physical cores vs logical CPUs

# Physical cores
grep "core id" /proc/cpuinfo | sort -u | wc -l

# Logical CPUs
nproc

On virtualized hosts or on systems with hyper-threading enabled, the physical and logical counts will not match. That distinction matters when you compare pricing or estimate capacity.

3. A small inventory script

echo "Model: $(lscpu | awk -F: '/Model name/ {gsub(/^ +/, "", $2); print $2; exit}')"
echo "Logical CPUs: $(nproc)"
echo "Physical cores: $(grep 'core id' /proc/cpuinfo | sort -u | wc -l)"

That output is handy for notes and migration checklists.

3.1 A batch collection pattern

Scenario Recommendation
Single host check Run commands directly
Fleet audit Write to a file
Asset registry Import into CMDB
#!/bin/bash
hostname
lscpu | awk -F: '/Model name|CPU\(s\)|Thread|Core/ {gsub(/^ +/, "", $2); print $1 ": " $2}'

4. When to check it

  • Before buying or migrating a server.
  • When a VM seems slower than expected and you want to rule out an instance mismatch.
  • Before benchmarking, so you can keep the hardware baseline consistent.

4.1 Combining the Signals

If you are planning a new server purchase, combine the hardware and deployment articles in the cloud servers category with the server selection guide and the server benchmark guide.

4.2 Common mistakes

Mistake Why it is a problem
Looking only at the model Core and thread counts matter too
Looking only at logical CPUs It does not equal physical capacity
Checking once only Specs can change after resize or migration

5. Reference note

Original post: https://www.cnblogs.com/cqzhuomi/articles/17297845.html (cnblogs.com CQZHUOMI, repost)

Keeping lscpu, nproc, and /proc/cpuinfo together in your records makes later performance comparisons much easier.

6. One more hardware check

If you also want to confirm the motherboard, BIOS, or machine serial number, CentOS 7 can expose that too.

dmidecode -t processor | grep -E 'Version|Core Count|Thread Count'
hostnamectl

These commands are easy to add to an inventory script. For operations records, it is better to capture the model, core count, thread count, and serial number in one pass so later troubleshooting is faster.

Field Use
Model Match purchase and instance spec
Core count Estimate performance
Thread count Judge concurrency
Serial number Asset registration

7. Put the results into an asset table

If you manage machines in bulk, record the CPU model, core count, thread count, memory, and disk in one asset table. That way you do not need to inspect each host again when you plan scaling, migration, or benchmarking.

Asset field Suggested content
Hostname Unique node identifier
CPU model Exact model string
Logical cores Result from nproc
Physical cores core id summary
Memory free -h
Disk lsblk

That may look simple, but it is extremely useful when you revisit a performance issue later. Many “the app is slow” cases end up being a hardware-spec mismatch.

If you also need to compare against benchmark results later, archive the lscpu output, the machine model, and the benchmark timestamp together. That lets you review how the same host behaved at different points in time without collecting the data again.

7.1 Record template

If you want to write this into a document, use a fixed template: hostname, CPU model, core count, thread count, memory, disk, and capture time. Once the template is standardized, side-by-side comparisons become much easier.

Field Example
Hostname web-01
Capture time 2026-08-07 10:00

You can go one step further and save the output of free -h and lsblk too. CPU is only part of the picture; memory and disk often end up being the real bottlenecks for user experience.

7.2 How to handle batch checks

If you manage multiple CentOS 7 machines, the easiest approach is not to log into each host manually. Put the commands into a small audit script so one run can capture the model, core count, thread count, and hostname in the same output. That makes it much easier to paste into a spreadsheet or ticket later.

#!/bin/bash
echo "Host: $(hostname)"
echo "Model: $(lscpu | awk -F: '/Model name/ {gsub(/^ +/, "", $2); print $2; exit}')"
echo "Logical CPUs: $(nproc)"
echo "Physical cores: $(grep 'core id' /proc/cpuinfo | sort -u | wc -l)"

7.3 A more useful inspection table

Check item Why it matters How to read it
Model Confirms the hardware spec Does it match the quote or instance plan?
Logical cores Indicates concurrency Is it enough for the workload?
Physical cores Shows actual compute capacity Are you being misled by hyper-threading?
Architecture Compatibility check Is it x86_64 or something else?
Cache Performance reference Is it suitable for heavy workloads?

7.4 Common troubleshooting scenarios

  1. After a VM upgrade, lscpu shows a different model string. First confirm whether the instance type actually changed.
  2. During benchmarking, the logical core count looks high but the results are mediocre. Check whether the gap comes from physical cores versus hyper-threading.
  3. If a fleet audit returns inconsistent values, inspect the image version and virtualization platform first.

If you want to preserve this data over time, have the audit script write the output directly to a text file or spreadsheet export. That keeps the information available for performance reviews, scaling decisions, and purchasing comparisons.

Integration & Code Examples

Example 1: Get the model, logical CPUs and physical cores in three commands

# 1) Model and architecture - lscpu reads far better than /proc/cpuinfo
lscpu | grep -E 'Architecture|Model name|^CPU\(s\)|Thread|Core|Socket'

# 2) Look at logical CPUs and physical cores separately
nproc
lscpu | awk -F: '/^Core\(s\) per socket/{c=$2} /^Socket\(s\)/{s=$2} END{print "physical cores: " c*s}'

# 3) Cross-check the model string and clock speed
grep -m1 'model name' /proc/cpuinfo
grep -m1 'cpu MHz' /proc/cpuinfo

# 4) Record memory and the system product name for asset inventory
free -h
dmidecode -s system-product-name 2>/dev/null

With hyper-threading on, nproc is twice the physical core count, so capacity planning should use Core(s) per socket times Socket(s).

Example 2: One inventory script that prints the full machine spec

#!/bin/bash
# /usr/local/bin/cpu-inventory.sh: one tab-separated spec line per host
printf '%s\t%s\t%s\t%s\t%s\t%s\n' \
  "$(hostname)" \
  "$(lscpu | awk -F: '/Model name/{gsub(/^ +/,"",$2); print $2; exit}')" \
  "$(nproc)" \
  "$(lscpu | awk -F: '/^Core\(s\) per socket/{c=$2} /^Socket\(s\)/{s=$2} END{print c*s}')" \
  "$(free -h | awk '/^Mem:/{print $2}')" \
  "$(date +%F' '%T)"

# Collect from several hosts, then align the output with column -t
chmod +x /usr/local/bin/cpu-inventory.sh
for h in web-01 web-02 db-01; do
  ssh "$h" /usr/local/bin/cpu-inventory.sh
done | column -t

Tab-separated output aligned with column -t is the most readable form; capture the timestamp too so before/after migration comparisons stay meaningful.

Limitations

  • That way you do not need to inspect each host again when you plan scaling, migration, or benchmarking.
  • This article reflects public information as of 2023-04-08; terms, prices and quotas follow the provider's current published terms.
  • Third-party capability and limit statements follow their official documentation; no further commitment is implied here.
  • Licensing, filing and data-residency decisions must be verified against the regulations of your operating region.

FAQ

What permissions does dmidecode require?

sudo, and only for BIOS or serial data. Reading /proc/cpuinfo, lscpu and nproc works for any account, which already covers model names, core counts and thread counts. Keep dmidecode as 1 separate step in the inventory script so routine collection stays unprivileged. That covers 90% of inventory needs.

Which command should I use for a CPU report?

lscpu for a report, /proc/cpuinfo for scripting. lscpu lays out architecture, cores, threads and cache as labelled fields, while cpuinfo repeats 1 block per logical CPU and needs grep plus uniq -c to aggregate. Record both, since capacity reviews usually ask for the raw output.

When should a CPU model alone be avoided?

When sizing or benchmarking a host. With hyper-threading, logical CPUs run close to 2x the physical core count, and under virtualization logical cores do not map to real compute. Capture cores per socket, socket count and architecture before load tests, so hardware variance is not read as a code problem.

Related Providers

  • Alibaba Cloud ECS: checking that an instance family matches the model reported in /proc/cpuinfo.
  • AWS EC2: instance types that change often, where vCPU counts must reconcile with the bill.
  • Hetzner: dedicated servers ordered by exact CPU model rather than by a marketing tier.

Community & Resources

Official docs and communities

Learning resources and tools

Original source: cnblogs.com (CQZHUOMI) ↗