Home Linux Commands How To Find Number Of CPU Cores From Commandline In Linux

How To Find Number Of CPU Cores From Commandline In Linux

By sk
Published: Updated: 33.4K views

When I am searching for ways to speed up compilation process, I needed to know how many CPU Cores are available in my Arch Linux system. After couple google searches, I found a few methods to find the number of CPUs/Cores from command line in Linux systems.

Find Number Of CPU Cores From Commandline In Linux

There might be several ways to find the number of CPU Cores in a system. Here is a few methods that I found online.

1. Using "nproc" command

The nproc is a simple Unix command to print the number of processing units available in your system. It is part of GNU Core utils, so it comes pre-installed with all modern Linux operating systems.

To display the number of cores in your system, open up your Terminal and run the following command:

$ nproc

As you see in the above example, my processor is 4-core type.

2. Using "lscpu" command

The "lscpu" command is used to display the information about your CPU in human-readable format. The lscpu command is part of the util-linux package, so don't bother about installation.

To find the CPU cores, run:

$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 42
Model name: Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz
Stepping: 7
CPU MHz: 799.890
CPU max MHz: 2300.0000
CPU min MHz: 800.0000
BogoMIPS: 4591.71
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx lahf_lm epb tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm arat pln pts

3. Using "top" command

The top command is used to display the dynamic real-time view of all running processes in your system.

To find out the CPU cores, run top command and press "1" (Number one) to get the CPU core details.

Find number of CPU cores in Linux using top command
Find number of CPU cores in Linux using top command

4. Using "/proc/cpuinfo"

There are few other ways to find way to find the cpu cores. One such a way is retrieve CPU core details from "/proc/cpuinfo" file.

$ cat /proc/cpuinfo | grep processor | wc -l

You can also do it using "grep" command as well.

$ grep -c processor /proc/cpuinfo


$ grep -c ^processor /proc/cpuinfo

5. Using "getconf" command

The "getconf" command has been around for a long time, and it is available for both Linux and Mac OS. If your system don't have the "nproc" or "lscpu" commands available, you can use "getconf" command to find out the number of cores as shown below.


You know now how to find the number CPUs/Cores from command line in Unix-like systems. Hope this was useful.

You May Also Like

1 comment

Stig February 27, 2021 - 3:25 pm

Although the article is well written then the headline is misleading. You don’t find the number of cores – you find the number of logical CPUs.
The ‘lscpu’ shows the facts on this. You are running an i3 with TWO cores with hyperthreading – which gives 4 logical CPUs.
This is minor, but cores and logical CPUs are not the same.

But, as said: Well written article.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More