CPU info in Ubuntu
How To

How to Get CPU Info in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

Curious about the brain of your computer? What kinds of architecture it has, and how many CPU cores it has? Who's the manufacturer? What's the model?

There are all kinds of processor information you can look for. And there are various kinds of commands and tools available for this purpose. Some of them show detailed output while some show only the essential ones.

As you can guess, this tutorial is about the hardware details, not CPU utilization.

Let me share various ways you can get processor details in Ubuntu command line.

Using lscpu command

The lscpu utility gathers CPU architecture info from sysfs and /proc/cpuinfo and can be found on most of the Linux distros.

lscpu

And I use lscpu quite often with my VMs as you get few cores:

sagar@ubuntuvm:~$ lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         45 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
  Model name:            12th Gen Intel(R) Core(TM) i5-12400
    CPU family:          6
    Model:               151
    Thread(s) per core:  1
    Core(s) per socket:  1
    Socket(s):           2
    Stepping:            5
    BogoMIPS:            4992.00
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mc
                         a cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall n
                         x pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good 
                         nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known
                         _freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x
                         2apic movbe popcnt tsc_deadline_timer aes xsave avx f16
                         c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fau
                         lt invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fs
                         gsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdse
                         ed adx smap clflushopt clwb sha_ni xsaveopt xsavec xget
                         bv1 xsaves arat umip pku ospke gfni vaes vpclmulqdq rdp
                         id movdiri movdir64b fsrm md_clear flush_l1d arch_capab
                         ilities
Virtualization features: 
  Hypervisor vendor:     VMware
  Virtualization type:   full
Caches (sum of all):     
  L1d:                   96 KiB (2 instances)
  L1i:                   64 KiB (2 instances)
  L2:                    2.5 MiB (2 instances)
  L3:                    36 MiB (2 instances)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0,1
Vulnerabilities:         
  Itlb multihit:         KVM: Mitigation: VMX unsupported
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Not affected
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
                          and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer
                          sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB fillin
                         g, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected
sagar@ubuntuvm:~$ 

As you can see, it goes in too much details on the CPU. It tells you the architecture, number of cores, manufacturer and a lot more details that you may not be interested in.

Checking the contents of /proc/cpuinfo file

You are not obligated to use the lscpu command. After all, it reads from the /proc/cpuinfo file so why not read it directly?

cat /proc/cpuinfo
use cat command to get cpu details in linux

It gets you info related to individual cores making it too long to read. But you can filter the results to get the relevantinfo.

To get view the vendor name:

cat /proc/cpuinfo | grep 'vendor' | uniq
sagar@Learnubuntu:~$ cat /proc/cpuinfo | grep 'vendor' | uniq
vendor_id	: GenuineIntel

To display model name:

cat /proc/cpuinfo | grep 'model name' | uniq	
sagar@Learnubuntu:~$ cat /proc/cpuinfo | grep 'model name' | uniq       
model name	: 12th Gen Intel(R) Core(TM) i5-12400

To count the number of processing units:

cat /proc/cpuinfo | grep processor | wc -l
sagar@Learnubuntu:~$ cat /proc/cpuinfo | grep processor | wc -l
12

Using dmidecode command

The dmidecode command gets the hardware info on Linux by dumping the computer's DMI (SMBIOS) table contents in a human-readable format.

While it avails users a variety of info, I will only fetch the CPU info by the given command:

sudo dmidecode --type processor
use dmidecode command to get cpu info in linux

Using inxi utility

The inxi is a script made for getting system info through the command line.

Though it does not come pre-installed in Ubuntu, you can easily install it.

sudo apt install inxi

As I'm only looking for CPU info, the intended results can be found by using -C option:

inxi -C
use inxi command to get cpu info in linux

Using cpuid

The cpuid commands will get every detail collected by CPUID instruction and can also discover the exact model of x86 CPU(s).

Ubuntu users can utilize the given command to install cpuid:

sudo apt install cpuid

And it can be executed by:

cpuid
use cpuid command to get cpu info in linux

Using lshw command

As its name suggests, the lshw utility is intended to list the hardware configuration of your system.

But I'm looking for CPU-specific details so the output can be filtered using -C option appending with CPU:

sudo lshw -C CPU
use lshw command to get cpu info in linux

Using hwinfo

Like the lshw command that I mentioned just above, the hwinfo command also gets the hardware details including CPU (of course).

But you have to go through the manual installation as it does not come pre-installed:

sudo apt install hwinfo

To get CPU info only, you just have to pair the hwinfo command with --cpu option:

hwinfo --cpu
get cpu info using hwinfo command in linux

Get the Number of Cores using nproc

If you are curious to know just the number of cores present in your system, then the nproc command will do the job.

nproc
get the number of cores present in linux using nproc command

Wrapping Up

This guide was a compilation of how you can get CPU info using different utilities. And the comments section welcomes you for queries!