Linux: Find Number of CPU Cores Command

How do I find out the number of CPU cores available under HP x86_64 Linux serer running on RHEL / Debian Linux 6.x?

You can use the lscpu or nproc command to display the number of processing units available to the current process, which may be less than the number of online processors (please note that not all server supports hotplug a CPU on a running Linux system).[donotprint]
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 1m

The proc file system is a pseudo-file system which is used as an interface to kernel data structures. It is commonly mounted at /proc. The /proc/cpuinfo file is nothing but a collection of CPU and system architecture dependent items, for each supported architecture a different list. Two common entries are processor which gives CPU number and bogomips; a system constant that is calculated during kernel initialization. SMP machines have information for each CPU.

nproc Example

The nproc command shows the number of processing units available:
# nproc
Sample outputs:


lscpu Command

lscpu gathers CPU architecture information form /proc/cpuinfon in human-read-able format:
# lscpu
Sample outputs:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    4
CPU socket(s):         2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 15
Stepping:              7
CPU MHz:               1866.669
BogoMIPS:              3732.83
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-7


The /proc/cpuinfo and sysfs stores info about your CPU architecture ike number of CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family, model, bogoMIPS, yte order and much more:
# less /proc/cpuinfo

Check out related media

Here is a quick demo of lscpu and /proc/cpuinfo commands:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 19 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
19 comments… add one
  • Hardly Wired Aug 13, 2012 @ 0:14

    Useful! You can also press ‘1’ when you run ‘top’ to get core info.

    • silencej Jun 5, 2013 @ 2:22

      Good one, thanks!

    • Junaid Dec 4, 2014 @ 5:05

      It was a good info.

    • Bruno Aug 7, 2015 @ 8:11

      Awesome. Thank you, that’s gonna help.

  • my2cents Aug 13, 2012 @ 2:03

    Great but… there is a but… You didn’t said that “lscpu” and “nproc” are only available on Debian like Linux !
    On one on my Ubuntu VM :

    root@wiki2:~# lscpu
    Architecture:          x86_64
    CPU op-mode(s):        32-bit, 64-bit
    Byte Order:            Little Endian
    CPU(s):                1
    On-line CPU(s) list:   0
    Thread(s) per core:    1
    Core(s) per socket:    1
    CPU socket(s):         1
    NUMA node(s):          1
    Vendor ID:             GenuineIntel
    CPU family:            6
    Model:                 15
    Stepping:              11
    CPU MHz:               2405.424
    BogoMIPS:              4810.84
    L1d cache:             32K
    L1i cache:             32K
    L2 cache:              4096K
    NUMA node0 CPU(s):     0
    root@wiki2:~# nproc

    On a Redhat Linux :
    lscup could be a simple ‘cat /proc/cpuinfo’ as there is no substitute !

    [root@web3 ~]# cat /proc/cpuinfo
    processor       : 0
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 15
    model name      : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz
    stepping        : 11
    cpu MHz         : 2405.424
    cache size      : 4096 KB
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 10
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm constant_tsc arch_perfmon pebs bts tsc_reliable aperfmperf unfair_spinlock pni ssse3 cx16 hypervisor lahf_lm dts
    bogomips        : 4810.84
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 40 bits physical, 48 bits virtual
    power management:

    and nproc as :

    [root@web3 ~]# grep -c processor /proc/cpuinfo

    ET voila !

    • Rajesh Jan 18, 2017 @ 7:04

      Thank you my2cents… it was really very helpfull

  • Pierre B. Aug 13, 2012 @ 8:18

    Just to add more one-liners , for RHEl box that do not come with nproc command:

    # Count the number of “physical processor(s)”
    grep "physical id" /proc/cpuinfo | sort -u | wc -l
    # Count the number of “physical cores per CPU”
    grep "cpu cores" /proc/cpuinfo |sort -u |cut -d":" -f2
    # Count the number of “logical cores ” (including multi-threading cores)
    grep -c "processor" /proc/cpuinfo
    • D Mar 26, 2013 @ 19:18

      Thanks Pierre, this was extremely helpful :) !!!!!

    • mrpurple Sep 1, 2015 @ 21:10

      Awesome. Here’s another based on yours
      # Count the total number of “physical cores”
      grep "cpu cores" /proc/cpuinfo |sort -u |cut -d":" -f2 | awk '{s+=$1} END {print s}'

  • Sam Aug 13, 2012 @ 11:01

    To find the number of cpu cores,

    cat /proc/cpuinfo| grep processor| wc -l

  • Pierre B. Aug 14, 2012 @ 7:52

    @ Sam :

    useless use of “| wc -l” : the -c option for grep would do the same …

    • ugogu Oct 2, 2015 @ 13:03

      …and useless use of “cat”. Grep does it all:
      grep -c processor /proc/cpuinfo

  • Bob Pelerson Dec 19, 2012 @ 22:45

    On FreeBSD dmesg |grep package
    produces something like
    2 package(s) x 6 core(s) x 2 SMT threads

  • nikhil c r Feb 17, 2014 @ 10:46

    thanks all of u…..

  • James Aug 30, 2014 @ 3:09

    As I understand it, the Intel Core i7 has four physical cores, expanded to eight by hyperthreading. So, readers should be aware that if they want to know the number of *physical* cores (without considering hyperthreading), these commands will not help.

  • Gabriel Nov 3, 2014 @ 18:19

    back to old days , simply cat /proc/acpi/processor | wc -l did the trick
    Now on debian derivates like Mint or *buntu nproc does the job
    For bash scripting , can be implemented a loop to enumerate all posibilities (rhell , debian , gentoo .. so forth ), if any enumerated functions is different than null , then break loop and pass info to variable
    It is usefull for pseudo parallel bash scripting when task has to be split into CPU core number.

  • Krapace Oct 19, 2015 @ 11:39

    And for GNU/Hurd ? i can’t find information :(

  • hani Mar 23, 2016 @ 5:57

    Thank you!

  • Richard Lloyd Apr 2, 2016 @ 10:07

    Although “grep -c processor /proc/cpuinfo” seems the best solution (utilities like nproc and lscpu are often not installed), it has a fatal flaw. It should be anchored to look at the start of the line for the “processor” string:

    grep -c ^processor /proc/cpuinfo

    This is because other lines of /proc/cpuinfo can contain “processor” – for example, a KVM-based VM has this:

    model name : Common KVM processor

    which will cause the original grep to double up the core count – whoops!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum