Check CPU number in Ubuntu
How To

Check the Number of CPUs in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

There are several cases when one would want to check the number of CPUs in Ubuntu such as checking cores before creating a VM or you want to see how powerful your system is.

So in this tutorial, I will walk you through the following ways to check the number of CPUs in Ubuntu:

  • Using lscpu command
  • Using nproc command
  • By printing the file content of the /proc/cpuinfo file
  • Using the dmidecode command

Let's start with the first one.

1. Using the lscpu command

The lscpu command is used to get installed processors info in variety and due to its rich feature set, it is the first preference by many users to get CPU info.

It comes pre-installed on most Linux systems and can be used without any additional options:

Use lscpu command to find number of CPUs in Ubntu

And as you can see, it gives tonnes of additional information which may not be what every user wants.

In that case, you can use the egrep in the following manner to sort the output:

lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
use lscpu command to find the number of cores in Ubuntu

As you can see, I have a CPU with 6 cores (but it shows 12. Then how?)

If you notice, thread per core is 2 so the total number will be multiplied by 2 which gave me 12 cores.

And if you're looking for physical cores, just divide CPU cores by the number of threads.

2. Using the nproc command

The whole purpose of using the nproc command is to get the number of cores. So if you're looking for the easiest option, here you have it.

To get the total number of cpu cores, simply execute nproc in your terminal:

use nproc command to find number of CPU in Ubuntu

3. By reading the file content of the /proc/cpuinfo file

This method gives similar output to the first method but with more details.

And being a file, all you need is the cat command to print its file contents:

cat /proc/cpuinfo
get the number of CPU cores by printing the contents of cpuinfo file

4. Using the dmidecode command

The dmidecode command uses the DMI (Desktop Management Interface) table of your system to retrieve information about your system hardware.

As it gives tonnes of additional information when used without any options, it is advised to use some flags to get the desired output:

sudo dmidecode -t 4 | egrep -i 'core (count|enabled)|thread count|Version'
use dmidecode command to find the number of CPU cores in Ubuntu

As you can see, it gives the number of physical cores (Core Count) and the total number of cores including threads.

This means it's close to perfect output for most users. A good way to check CPU count in Linux.

Get more details about your CPU

If you want additional information apart from CPU cores, we made a dedicated tutorial on that topic:

How to Get CPU Info in Ubuntu
Here are various ways for getting the processor information in Ubuntu command line.

And get some details on current CPU usage:

Check CPU usage in Ubuntu
Learn how to check the CPU usage in Ubuntu command line.

I hope you will find this guide helpful.

Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.