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
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 4
As you see in the above example, my processor is 4-core type.
2. Using "lscpu" command
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
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.
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 "
$ cat /proc/cpuinfo | grep processor | wc -l 4
You can also do it using "grep" command as well.
$ grep -c processor /proc/cpuinfo 4
$ grep -c ^processor /proc/cpuinfo 4
5. Using "getconf" command
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.
$ getconf _NPROCESSORS_ONLN 4
You know now how to find the number CPUs/Cores from command line in Unix-like systems. Hope this was useful.
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.