lscpu Command in Linux: CPU Architecture, Cores & JSON Output

Deepak Prasad
Tested on Ubuntu 25.04 (Plucky Puffin)
Package lscpu from util-linux 2.40.2
lscpu from util-linux 2.40.2
Applies to Ubuntu, Debian, RHEL, Fedora
Privilege sudo or root
Man page lscpu(1)
Scope lscpu prints CPU topology from sysfs and /proc/cpuinfo — sockets, cores, threads, NUMA nodes, caches, and flags. Use it for capacity planning, affinity tuning, and JSON export to monitoring scripts.
Related guides Linux commands

lscpu — quick reference

Summary view

Human-readable overview of architecture, CPUs, sockets, caches, and security mitigations.

When to use Command
Default CPU summary lscpu
Print sizes in bytes instead of KiB/MiB lscpu -B
Print cache details in extended table lscpu -C
Use JSON for the default summary lscpu -J
Show CPU masks in hexadecimal lscpu -x
Use physical CPU IDs instead of logical lscpu -y

Extended and parsable lists

Per-CPU rows for scripts — pair with -e (readable) or -p (CSV-like).

When to use Command
Extended readable CPU list lscpu -e
Limit extended columns lscpu -e=cpu,core,socket
Parsable format for scripts lscpu -p
Limit parse columns lscpu -p=cpu,core
Include offline CPUs in list lscpu -a -e
Online CPUs only in list lscpu -b -e
Offline CPUs only lscpu -c -e

Other

When to use Command
Read CPU info from a chroot or mounted root lscpu --sysroot /path
Indent related summary fields with subsections lscpu --hierarchic=always
Show all available columns for -e, -p, or -C lscpu --output-all -e
Per-CPU layout as JSON lscpu -J -e
Show built-in usage text lscpu --help
Show util-linux version lscpu --version

lscpu — command syntax

Synopsis from lscpu --help on Ubuntu 25.04 (util-linux 2.40.2):

text
Usage:
 lscpu [options]

Display information about the CPU architecture.

Options:
 -a, --all               print both online and offline CPUs (default for -e)
 -b, --online            print online CPUs only (default for -p)
 -B, --bytes             print sizes in bytes rather than in human readable format
 -C, --caches[=<list>]   info about caches in extended readable format
 -c, --offline           print offline CPUs only
 -J, --json              use JSON for default or extended format
 -e, --extended[=<list>] print out an extended readable format
 -p, --parse[=<list>]    print out a parsable format
 -s, --sysroot <dir>     use specified directory as system root
 -x, --hex               print hexadecimal masks rather than lists of CPUs
 -y, --physical          print physical instead of logical IDs
     --hierarchic[=when] use subsections in summary (auto, never, always)
     --output-all        print all available columns for -e, -p or -C

 -h, --help              display this help
 -V, --version           display version

Data comes from sysfs (/sys/devices/system/cpu/) and /proc/cpuinfo. No config files are modified.


lscpu — command examples

Essential Default CPU summary

Start here for core count, model name, architecture, and cache sizes.

Run the command:

bash
lscpu | head -20

Sample output:

output
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Byte Order:                              Little Endian
CPU(s):                                  2
On-line CPU(s) list:                     0,1
Model name:                              Intel(R) Core(TM) Ultra 5 135U
Thread(s) per core:                      1
Core(s) per socket:                      2
Socket(s):                               1
Stepping:                                4
L1d cache:                               64 KiB (2 instances)
L1i cache:                               128 KiB (2 instances)
L2 cache:                                4 MiB (2 instances)
L3 cache:                                24 MiB (2 instances)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0,1

CPU(s) is logical processors; compare with Core(s) per socket × Socket(s) for capacity planning.

Essential Per-CPU extended list with -e

See how logical CPUs map to cores, sockets, and NUMA nodes.

Run the command:

bash
lscpu -e

Sample output:

output
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
  0    0      0    0 0:0:0:0          yes
  1    0      0    1 1:1:1:1          yes

Each row is one logical CPU. The cache column shows shared cache indices for that CPU.

Essential Parsable output for scripts with -p

Machine-friendly comma-separated lines — comment header explains columns.

Run the command:

bash
lscpu -p | head -5

Sample output:

output
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting usually from zero.
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
0,0,0,0,,0,0,0,0
1,1,0,0,,1,1,1,1

Import into spreadsheets or awk without parsing the human summary.

Common JSON export with -J

Monitoring tools and configuration management often consume JSON.

Run the command:

bash
lscpu -J | head -25

Sample output:

output
{
   "lscpu": [
      {
         "field": "Architecture:",
         "data": "x86_64"
      },{
         "field": "CPU op-mode(s):",
         "data": "32-bit, 64-bit"
      },{
         "field": "CPU(s):",
         "data": "2"
      },{
         "field": "Model name:",
         "data": "Intel(R) Core(TM) Ultra 5 135U"
      }
   ]
}

Pipe to jq to extract one field in automation.

Common Cache hierarchy with -C

Detailed L1/L2/L3 table — size, type, associativity, and level.

Run the command:

bash
lscpu -C

Sample output:

output
NAME ONE-SIZE ALL-SIZE WAYS TYPE        LEVEL  SETS PHY-LINE COHERENCY-SIZE
L1d       32K      64K    8 Data            1    64        1             64
L1i       64K     128K    8 Instruction     1   128        1             64
L2         2M       4M   16 Unified         2  2048        1             64
L3        12M      24M   12 Unified         3 16384        1             64

Use this when tuning CPU affinity or explaining cache sizes in support tickets.

Common Select columns with -e=cpu,core

Trim extended output to the fields your script needs.

Run the command:

bash
lscpu -e=cpu,core

Sample output:

output
CPU CORE
  0    0
  1    1

Available column names appear in lscpu --help under "Available output columns".

Advanced Hexadecimal CPU masks with -x

Affinity masks in hex — matches how some kernel APIs report sets.

Run the command:

bash
lscpu -x | head -12

Sample output includes lines like:

text
On-line CPU(s) mask:                     3
NUMA node0 CPU(s):                       3

Mask 3 (hex) means CPUs 0 and 1 are online — useful when comparing with taskset or cgroup cpuset settings.

Advanced List offline CPUs with -c -e

On systems that hot-plug CPUs, see which logical processors are marked offline.

Run the command:

bash
lscpu -c -e

When every CPU is online, the table has no rows. On larger servers you may see rows with ONLINE set to no.


lscpu — when to use / when not

Use lscpu when Use something else when
  • You need kernel-reported CPU count, sockets, cores, threads, or NUMA layout
  • You want cache sizes or JSON/parsable output for scripts
  • You check which logical CPUs are online or offline
  • You inspect CPU layout from a mounted root with --sysroot
  • You need full hardware inventory (disks, buses) → lshw
  • You need firmware serial numbers or BIOS CPU records → dmidecode
  • You only need a processor count → nproc
  • You measure live CPU utilization → top
  • You change runtime affinity → taskset or numactl

lscpu vs lshw vs dmidecode

lscpu lshw dmidecode
Focus CPU topology Full hardware tree DMI/SMBIOS tables
Privilege None Root for full detail Root for full detail
Data source sysfs, /proc/cpuinfo DMI, PCI, … DMI
Best for Core counts, NUMA, caches Inventory audits Vendor serials, BIOS

lscpu — interview corner

Where does lscpu get its data?

lscpu reads sysfs under /sys/devices/system/cpu/ and /proc/cpuinfo. It does not probe hardware directly — the kernel exports topology there. That makes it fast and non-invasive compared to lshw.

A strong answer is:

"sysfs and /proc/cpuinfo — kernel-exported topology. lscpu formats it for humans or JSON without root."

What is the difference between CPU(s) and Core(s) per socket?

CPU(s) in lscpu is the count of logical processors (includes hyper-threading). Core(s) per socket is physical cores per chip. Multiply cores × sockets for physical cores; compare with CPU(s) to see if SMT is enabled.

bash
lscpu | grep -E 'CPU\(s\)|Core|Socket|Thread'

A strong answer is:

"CPU(s) is logical processors; cores per socket times sockets is physical cores. Threads per core above one means hyper-threading."

When use lscpu -e vs -p?

-e prints an extended human-readable table — good for admins. -p prints comma-separated rows with a comment header — good for awk, Python, and CMDB import. Both accept column lists: -e=cpu,core,node.

A strong answer is:

"-e for readable per-CPU tables; -p for script parsing. I trim columns with -e=cpu,core when I only need mapping."

How do you read NUMA information from lscpu?

Look for NUMA node(s) and NUMA nodeN CPU(s) in the summary — they list which logical CPUs belong to each node. Use -e=cpu,node for a per-CPU table. Pair with numactl --hardware when tuning memory locality.

A strong answer is:

"NUMA node lines in lscpu show node count and CPU lists; -e=cpu,node gives per-CPU mapping for affinity planning."

How do you export lscpu data to JSON?

Run lscpu -J. Output is a JSON array of field/data pairs suitable for jq:

bash
lscpu -J | jq -r '.lscpu[] | select(.field=="CPU(s):") | .data'

A strong answer is:

"lscpu -J for JSON; I pipe through jq in Ansible or monitoring to grab CPU count or model name."


Troubleshooting

Symptom Likely cause Fix
lscpu: command not found util-linux missing sudo apt install util-linux
-a without -e/-p ignored -a only applies to list modes Use lscpu -a -e
Wrong counts inside VM Virtual topology differs from host Trust guest view for guest tuning; check hypervisor vCPU assignment
-s sysroot empty Path lacks /proc and /sys Point at a mounted guest root or use chroot
Missing cache lines Old kernel or restricted sysfs Upgrade kernel; compare with /proc/cpuinfo

Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.

  • Linux
  • HTML5
  • JavaScript
  • Web Design
  • Front-end Web Development