How do I find out the number of cores my CPU has, including virtual cores (hyper threading cores) using the command line?


You can count no of CPUs

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

Output :


To check the number of cores !

cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 1


 $ nproc

Or lscpu will show you all output:


Architecture:          i686
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
Vendor ID:             GenuineIntel
CPU family:            15
Model:                 4
Stepping:              7
CPU MHz:               2792.992
BogoMIPS:              5585.98
L1d cache:             16K
L2 cache:              1024K
  • 5
    grep can count matches with -c option, no need in wc. – Ruslan Jan 22 '16 at 20:45
  • 1
    i.e. the first command is equivalent to grep -c processor /proc/cpuinfo – arun Nov 17 '17 at 23:05
  • nproc is also useful in scripts depending on the number of cores available to it. E.g. make -j$(nproc). – Farway Dec 11 '18 at 19:45

To add to the existing answers, you can determine information about Intel's HyperThreading by looking at the "siblings" line in /proc/cpuinfo. The example below is from a 2 socket machine. It shows the CPU has 6 cores but 12 "siblings". On Intel CPUs this means HyperThreading is enabled and there are 6 physical cores.

processor       : 23
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Xeon(R) CPU E5-2430 v2 @ 2.50GHz
stepping        : 4
microcode       : 0x428
cpu MHz         : 1599.707
cache size      : 15360 KB
physical id     : 1
siblings        : 12
core id         : 5
cpu cores       : 6
apicid          : 43
initial apicid  : 43
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
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 pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5005.20
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

dmidecode is also useful for determining what hardware a Linux system is running on.


/proc/cpuinfo contains all the CPUs for my computer, including virtual. You can count them with a little grep:

grep -Pc '^processor\t' /proc/cpuinfo

Assuming you don't turn off your cores/threads, this command will answer your question:

  • This will show the number of cores Online which can be different from the total number of cores.. – heemayl Jan 22 '16 at 20:23
  • 1
    @heemayl that's why I started the answer as I did. – Ruslan Jan 22 '16 at 20:44
  • makes sense..i have overlooked that.. +1 – heemayl Jan 22 '16 at 20:45

You can also install htop (a fancier version of top) which will show you all your cores.

sudo apt-get install htop

Then start it: htop



 lscpu |grep 'CPU(s)'

You will get among other few lines, this one:

CPU(s)                  4

You can get 1, 2 ... in place of 4, depending on your CPU, and that is the number of cores your CPU has.

  • This gives the number of CPUs, not the number of cores. – kaushalpranav Jun 28 '18 at 8:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.