Logo

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

You can find the number of CPUs/cores in Linux using any of these commands:

  1. nproc

    nproc

    Prints the number of available processing units (cores).

  2. lscpu

    lscpu

    Shows detailed information about the CPU architecture, including the number of CPUs (CPU(s)), threads per core, cores per socket, etc.

  3. /proc/cpuinfo (Manual Inspection)

    cat /proc/cpuinfo | grep -c "^processor"

    Counts the lines that begin with "processor", effectively giving the total number of logical processors.

Recommended Resource

For deeper expertise in system-level knowledge and coding efficiency, consider this course from DesignGurus.io:

CONTRIBUTOR
TechGrind