Linux Find Number of CPU Cores Command

See all GNU/Linux related FAQ
How do I find out the number of CPU cores available under HP x86_64 Linux serer running on RHEL / Debian / Ubuntu Linux?

You can use the lscpu command 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. This page explains how to find number of CPU cores on Linux using the command-line options.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux terminal
Category System Management
OS compatibility AlmaLinux Alpine Arch Debian Fedora Mint openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu WSL
Est. reading time 2 minutes

Finding number of CPU cores on Linux

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 including number of CPU cores on Linux.

nproc command examples

The nproc command shows the number of processing units available on your Linux machine, run:
$ nproc
Here is what I see:

8

Sometimes it may not print all the number of installed processors (CPUs). Hence, pass the --all option too:
$ nproc --all
I got 12 as logical core number output.

How To - Linux Find Number of CPU Cores Command

How to find CPU cores count on Linux (click to enlarge)

Using lscpu Linux command to list number of CPU cores on my machine

The lscpu command 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 file

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 using the less command or more command as follows:
# less /proc/cpuinfo
Use the grep command and egrep command as follows:
$ grep -c processor /proc/cpuinfo

Check out related media

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

Summing up

You learned how to find out number of CPU cores count on Linux using the CLI options. Do read the following manual pages using the man command or help command $ man lscpu
$ man nproc
$ man 5 proc

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

20 comments… add one
  • 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!

  • Kathy Apr 2, 2022 @ 10:07

    These are very useful commands for my Java app need to find out requirements that needs to be on AWS cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.