Linux Commands

How to Find How Many Cores There are in Linux Systems

This tutorial explains how many processor cores there are in a Linux system.

After reading this article, you will be able to check the number of cores through different available commands for all Linux systems. Some of the explained commands are also useful in BSD systems.

All instructions described in this tutorial include screenshots for every user to understand easily, independently of his knowledge level.”

To check the number of CPUs in Linux, this tutorial covers the following commands:

The lscpu Command

The lscpu command reads both the sysfs file system and the /proc/cpuinfo file. By executing lscpu, we can see how many cores there are in our Linux system. Additionally, this command shows the information on CPU caches, model, and sockets, among other useful information.

This section explains how to use lscpu to print all CPU information and how to show the number of CPU cores specifically.

To display all CPU information, run lscpu without additional flags, as shown in the figure below.


By using egrep, you can print only the number of cores, as shown below.

lscpu | egrep 'CPU\(s\)'

The lscpu command is the most widely used to check information on CPUs.

Check the Number of Cores in Linux With the nproc Command

Another simple to use tool to reveal the number of cores in your Linux system is the nproc command.

By default, without flags, this command displayed the core number. Just run the command as shown below for it to return the number of cores in the system.


As you can see, the output is extremely simple.

The hwinfo Command

The hwinfo Linux command is another option to check the number of cores on the system.

The hwinfo command is not included by default on Linux systems. To install it on Debian-based Linux distributions, use the apt packages manager as shown in the screenshot below.

sudo apt install hwinfo -y

Once installed, run the hwinfo command followed by the flags shown in the following figure.

sudo hwinfo --cpu --short

As you can see, the number of cores is returned line by line.

The hwinfo command can be used to print information about all hardware in the system.

Among its features, you can export the output to a file. To export the number of cores to a file, use the following syntax.

Note: The exported file name is arbitrary; you can name it as you want.

sudo hwinfo --short --cpu > cores.txt

You can use the less command to read the exported file.

less cores.txt

As you can see below, the file content is the same as the previous output.

To show all system information with hwinfo, run it as shown in the following figure.

sudo hwinfo --all

As shown in the screenshot above, the hwinfo command is not user-friendly when displaying information on all the hardware. For a more user-friendly view, use the –short flag to specify the hardware you want to check, as shown in the first example of the hwinfo section.

Finding the Number of CPUs in Linux Using the Top Command

The Linux top (table of processes) command is a task manager that prints real-time Memory and CPU resource usage.

This command prints executing processes and memory and CPU consumption. When used with the -1 flag, it also shows the number of cores in the system.

Run the following command to start the top utility showing how many cores are present in the system.

top -1

As you can see, the top command shows 4 cores: 0,1,2, and 3.

Additionally, you also can run the top command without flags and then press 1; the result is the same.

Checking How Many Cores Using the htop Command

The htop command is similar to the top command previously explained. But it has some advantages over the top. The htop user interface is colorful, therefore more user friendly, htop also supports scrolling,

Contrary to the top, to see how many cores are in the system, you don’t need to use flags. Run the command below to see how htop displays the cpu information.


Reveal Number of Cores in Linux by Reading /proc/cpuinfo

Another way to see the number of cores in Linux is by reading the /proc/cpuinfo file. You can use different commands to read this file, like less, cat, more, etc.

To read the cpuinfo file, run the command shown below.

less /proc/cpuinfo

The number of cores is shown in the siblings line, as pointed out by the white arrow in the screenshot below.

You also can specifically show the number of cores by running the command below.

less /proc/cpuinfo | grep processor | wc -l

As you can see below, there are 4 cores in the system.

That’s all; with all commands described above, you have different ways to check the number of cores.


As shown in this tutorial, under Linux, there are many methods to check the number of cores on the system. All methods are easy to apply by any user, independently of the expertise level. The above commands are universal and available for all Linux distributions, even when not installed by default with the system. Learning the number of cores is important, for example, when assigning processor resources to virtual machines. Every Linux user must know how to gather information about the hardware.

Thank you for reading this tutorial explaining how to find how many cores there are in the system. Keep following LinuxHint for more Linux professional tutorials and tips.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.