How to obtain the number of CPUs/cores in Linux from the command line?

The Solution to How to obtain the number of CPUs/cores in Linux from the command line? is


grep -c ^processor /proc/cpuinfo     

will count the number of lines starting with "processor" in /proc/cpuinfo

For systems with hyper-threading, you can use

grep ^cpu\\scores /proc/cpuinfo | uniq |  awk '{print $4}' 

which should return (for example) 8 (whereas the command above would return 16)

~ Answered on 2011-06-25 22:56:01


Most Viewed Questions: