Display Number of Processors on Linux
If you've just upgraded your Linux box, or you are wondering how many processors a remote server has, there's a quick and dirty command you can use to display the number of processors.
On Linux, /proc/cpuinfo contains all of the processor information for all current processors in your computer. This will include the speed, the amount of on-chip cache, processor type, and how many cores.
Here's the command:
cat /proc/cpuinfo | grep processor | wc -l
The command just looks in the /proc/cpuinfo file, pulls out the number of lines containing the word "processor" and passes them into wc (word count), which returns a count of the CPUs in the system.
Here's what it returned on my remote server:
[root@root]# cat /proc/cpuinfo | grep processor | wc -l
4
Note that if you have a dual-core processor, it will return each core as a separate processor. You can look at the full output of cat /proc/cpuinfo to see if the chips are dual-core.


Hi,
this will give you the same result and saves you having to type a couple of characters
grep processor /proc/cpuinfo |wc -l
This will save you a pipe
grep -c processor /proc/cpuinfo
Won't this count CPUs with hyperthreading twice? My computer has one Pentium 4 (Prescott) CPU, but has two processor entries in cpuinfo.
Well… Sorry to say that it doesn't work most of the time. Beside multithreadin processors, It is common that entry on a single processor has multiple occurence of word "processor" (both in the procesor identifier and model name.
On my ancient pemtium M laptop it reports 2 processors because ist modelname is "Intel(R) Pentium(R) M processor 1.73GHz".
This might help:
grep -c ^processor /proc/cpuinfo
To get the count of physical CPUs, this works by counting the unique physical ids
grep "physical id" /proc/cpuinfo |sort -u|wc -l