Get Number of CPU Cores on Linux Debian

Posted on May 3, 2020 at 10:51 pm

Get the correct number of CPU cores on a Linux Debian server:

grep "cpu cores" /proc/cpuinfo |sort -u |cut -d":" -f2 | awk '{s+=$1} END {print s}'

Here is an example output on an AMD Ryzen 5 3600 Hexa-Core:


That is correct, the CPU has 6 cores and 12 threads.

If you have multiple sockets, just count the number of sockets (CPUs):

echo $(($(grep "^physical id" /proc/cpuinfo | awk '{print $4}' | sort -un | tail -1)+1))

Multiply the CPU cores number by the number of sockets.

To get number of CPU threads use:

nproc --all

Receive updates via email

Other Posts

Updated Posts