Richard Richard - 1 year ago 108
Linux Question

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

I have this script, but I do not know how to get the last element in the printout:

cat /proc/cpuinfo | awk '/^processor/{print $3}'

The last element should be the number of CPUs, minus 1.

Answer Source
cat /proc/cpuinfo | awk '/^processor/{print $3}' | tail -1

or simply

grep -c ^processor /proc/cpuinfo     

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download