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

How To Find Number Of CPU Cores From Commandline In Linux

By sk
13413 Views

When I am searching for ways to speed up compilation process in Arch Linux, I needed to know the number CPU cores in my Linux system. After a couple web searches, I found a few methods to find number CPU Cores in Linux from commandline. For those who wanted to know how many CPU Cores are in their Linux and Unix-like systems, this brief guide will help.

Find Number Of CPU Cores From Commandline In Linux

There might be several ways to find the number of CPU Cores in a Linux system. Here is a few methods that I am aware of now.

1. Using "nproc" command

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

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

$ nproc
4

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

Find number CPU Cores in Linux using nproc command

Find number CPU of Cores in Linux using nproc command

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.

Run "lscpu" command without any options to display the number of CPU cores in Linux:

$ lscpu

Sample output:

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
Display number of CPU Cores in Linux using lscpu command

Display number of CPU Cores in Linux using lscpu command

3. Using "top" command

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

To view the number of 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"

The /proc is a special virtual filesystem in Linux and Unix-like distributions. It is also known as process information pseudo-file system. It doesn't contain any 'real' files but runtime system information such as processes, system memory, mounted devices and hardware configuration etc. Each device details are stored in a separate directory under /proc directory. The CPU information is stored in "/proc/cpuinfo" file.

To get the number of CPU core details from "/proc/cpuinfo" file, run:

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

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

$ grep -c processor /proc/cpuinfo
4

Or,

$ grep -c ^processor /proc/cpuinfo
4
View number of CPU cores in Linux

View number of CPU cores in Linux

5. Using "getconf" command

The "getconf" command is used to query and display the configuration variables and their values in Linux. It has been around for a long time, and it is available for both Linux and Mac OS.

Use "getconf" command to find out the number of cores in a Linux system as shown below:

$ getconf _NPROCESSORS_ONLN
4

These are a few ways to find the number CPUs/Cores from command line in Linux and Unix-like systems. Hope this was useful.

Related read:

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.

Reply

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. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More