nproc Command
Beginner System Information man(1)Print the number of processing units available
👁 9 views
📅 Updated: Mar 15, 2026
SYNTAX
nproc [OPTION]...
What Does nproc Do?
nproc prints the number of available processing units (CPU cores/threads). It is the simplest way to determine how many parallel tasks the system can handle.
nproc is commonly used with make -j for parallel compilation and with xargs -P for parallel command execution. It respects cgroup limits in containers, making it more accurate than parsing /proc/cpuinfo.
nproc outputs a single number, making it perfect for command substitution in scripts.
nproc is commonly used with make -j for parallel compilation and with xargs -P for parallel command execution. It respects cgroup limits in containers, making it more accurate than parsing /proc/cpuinfo.
nproc outputs a single number, making it perfect for command substitution in scripts.
Options & Flags
| Option | Description | Example |
|---|---|---|
| (no args) | Show available processors | nproc |
| --all | Show all installed processors | nproc --all |
Practical Examples
#1 Get CPU count
Shows the number of available processing units.
$ nproc
Output:
8
#2 Parallel make
Compiles using all available CPU cores.
$ make -j$(nproc)#3 Parallel xargs
Processes images in parallel using all cores.
$ find . -name '*.png' | xargs -P $(nproc) -I {} convert {} -resize 50% {}#4 Leave one core free
Compiles using all cores except one, keeping system responsive.
$ make -j$(($(nproc) - 1))#5 All vs available
Shows available vs total processors (may differ in containers).
$ echo "Available: $(nproc), Total: $(nproc --all)"
Output:
Available: 4, Total: 8
Tips & Best Practices
Use with make -j: make -j$(nproc) is the standard way to parallelize compilation. It uses all available cores automatically.
Container awareness: nproc respects cgroup CPU limits in containers. If a container is limited to 2 cores, nproc returns 2.
Leave cores for the system: For long-running background tasks, use nproc - 1: make -j$(($(nproc) - 1)) to keep the system responsive.
Frequently Asked Questions
How do I find the number of CPU cores?
nproc returns the count of available processing units. Use nproc --all for total installed.
How do I compile using all cores?
make -j$(nproc) automatically uses all available CPU cores for parallel compilation.
Does nproc show physical or logical cores?
nproc shows logical processors (including hyperthreads). On a 4-core CPU with hyperthreading, it shows 8.
Related Commands
More System Information Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →