lscpu Command

The lscpu command displays detailed information about the CPU architecture and processor specifications. It gathers CPU information from sysfs, /proc/cpuinfo, and other system sources to provide comprehensive hardware details.

Syntax

lscpu [OPTIONS]

Description

The lscpu command provides detailed information about the CPU architecture, including processor type, number of cores and threads, cache sizes, frequencies, and various CPU features.

Key features:

  • Display CPU architecture information
  • Show processor specifications
  • Report cache sizes and hierarchy
  • Display CPU frequencies and scaling
  • Show virtualization capabilities
  • Provide parseable output formats
Note: lscpu gathers information from /proc/cpuinfo, sysfs, and other kernel interfaces. Some information may not be available on all systems.

Common Options

Option Description
-a, --all Include lines for online and offline CPUs in extended format
-b, --online Limit output to online CPUs (default for -e)
-c, --offline Limit output to offline CPUs
-e, --extended[=list] Show CPU information in extended readable format
-p, --parse[=list] Optimize output for easy parsing by scripts
-s, --sysroot dir Gather CPU data for a Linux instance other than running system
-x, --hex Use hexadecimal masks for CPU sets
-y, --physical Show physical IDs for all columns
--output-all Output all available columns
-h, --help Display help message and exit
-V, --version Display version information and exit

Examples

Basic CPU information

lscpu

Display comprehensive CPU architecture information

Extended format output

lscpu -e

Show CPU information in extended table format

Parseable output

lscpu -p

Generate machine-readable output for scripts

Show all CPUs (online and offline)

lscpu -e -a

Display information for both online and offline CPUs

Only offline CPUs

lscpu -e -c

Show information only for offline CPUs

Specific columns in extended format

lscpu -e=CPU,CORE,SOCKET,NODE

Display only specified columns in extended format

Parseable format with specific columns

lscpu -p=CPU,CORE,SOCKET

Generate parseable output with only specified columns

Use hexadecimal masks

lscpu -x

Display CPU sets using hexadecimal masks

Understanding lscpu Output

Basic Output Format

$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 39 bits physical, 48 bits virtual CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 142 Model name: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz Stepping: 12 CPU MHz: 1800.000 CPU max MHz: 4600.0000 CPU min MHz: 400.0000 BogoMIPS: 3999.93 Virtualization: VT-x L1d cache: 128 KiB L1i cache: 128 KiB L2 cache: 1 MiB L3 cache: 8 MiB NUMA node0 CPU(s): 0-7 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

Example of basic lscpu output showing comprehensive CPU information

Extended Format Output

$ lscpu -e CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ 0 0 0 0 0:0:0:0 yes 4600.0000 400.0000 1 0 0 0 0:0:0:0 yes 4600.0000 400.0000 2 0 0 1 1:1:1:0 yes 4600.0000 400.0000 3 0 0 1 1:1:1:0 yes 4600.0000 400.0000 4 0 0 2 2:2:2:0 yes 4600.0000 400.0000 5 0 0 2 2:2:2:0 yes 4600.0000 400.0000 6 0 0 3 3:3:3:0 yes 4600.0000 400.0000 7 0 0 3 3:3:3:0 yes 4600.0000 400.0000

Extended format showing CPU topology in table format

Parseable Format Output

$ lscpu -p # The following is the parseable format, which can be fed to other # programs. Each different item in every column has an unique ID # starting from zero. # CPU,Core,Socket,Node,,L1d,L1i,L2,L3 0,0,0,0,,0,0,0,0 1,0,0,0,,0,0,0,0 2,1,0,0,,1,1,1,0 3,1,0,0,,1,1,1,0 4,2,0,0,,2,2,2,0 5,2,0,0,,2,2,2,0 6,3,0,0,,3,3,3,0 7,3,0,0,,3,3,3,0

Parseable format suitable for script processing

Key Information Fields

Architecture Information

Field Description
Architecture CPU architecture (x86_64, i386, arm64, etc.)
CPU op-mode(s) Supported operating modes (32-bit, 64-bit)
Byte Order Endianness (Little Endian, Big Endian)
Address sizes Physical and virtual address space sizes

CPU Topology

Field Description
CPU(s) Total number of logical CPUs
Thread(s) per core Number of threads per physical core
Core(s) per socket Number of physical cores per socket
Socket(s) Number of physical CPU sockets
NUMA node(s) Number of NUMA nodes

Processor Details

Field Description
Vendor ID CPU manufacturer (GenuineIntel, AuthenticAMD)
Model name Full processor model name and specifications
CPU MHz Current CPU frequency
CPU max MHz Maximum CPU frequency
CPU min MHz Minimum CPU frequency
Virtualization Virtualization technology support

Cache Information

Cache Level Description
L1d cache Level 1 data cache size
L1i cache Level 1 instruction cache size
L2 cache Level 2 cache size
L3 cache Level 3 cache size

Practical Use Cases

System Analysis

Check CPU specifications

# Get basic CPU information lscpu # Extract specific information lscpu | grep "Model name" lscpu | grep "CPU(s):" lscpu | grep "Thread(s) per core"

Analyze system CPU specifications for performance planning

Performance tuning information

# Check CPU topology for optimization lscpu -e # Get cache information lscpu | grep cache # Check frequency scaling lscpu | grep MHz

Gather information for performance optimization

Scripting and Automation

Extract specific CPU information

# Get number of CPUs lscpu | grep "^CPU(s):" | awk '{print $2}' # Get CPU model lscpu | grep "Model name" | cut -d: -f2 | sed 's/^ *//' # Get architecture lscpu | grep "Architecture" | awk '{print $2}'

Extract specific information for scripts and automation

Generate parseable output for scripts

# CSV format for processing lscpu -p=CPU,CORE,SOCKET,NODE | grep -v "^#" # Process with awk lscpu -p | awk -F, '/^[0-9]/ {print "CPU " $1 " is on core " $2}'

Generate machine-readable output for automated processing

Virtualization and Cloud

Check virtualization support

# Check for virtualization features lscpu | grep Virtualization # Check CPU flags for virtualization lscpu | grep Flags | grep -o "vmx\|svm"

Verify virtualization capabilities for VM deployment

NUMA topology analysis

# Check NUMA configuration lscpu | grep NUMA # Extended NUMA information lscpu -e | grep NODE

Analyze NUMA topology for memory optimization

Comparing with Other Commands

lscpu vs /proc/cpuinfo

# lscpu provides structured output lscpu # /proc/cpuinfo shows raw kernel data cat /proc/cpuinfo # lscpu processes and summarizes /proc/cpuinfo lscpu | grep "CPU(s):" grep -c processor /proc/cpuinfo

lscpu provides more organized and summarized information

lscpu vs nproc

# lscpu shows detailed topology lscpu | grep "CPU(s):" # nproc shows available processors nproc # Both should show same number for online CPUs lscpu --online -p | grep -v "^#" | wc -l

nproc is simpler for just getting CPU count

lscpu vs lshw

# lscpu focuses on CPU architecture lscpu # lshw shows broader hardware information lshw -class processor # lscpu is more detailed for CPU-specific info

lscpu provides more detailed CPU-specific information

Advanced Usage

Custom Column Selection

Extended format with specific columns

# Show only CPU, Core, and Socket information lscpu -e=CPU,CORE,SOCKET # Include cache information lscpu -e=CPU,CORE,SOCKET,L1d,L1i,L2,L3 # Show frequency information lscpu -e=CPU,MAXMHZ,MINMHZ

Customize output to show only relevant information

Parseable format with custom columns

# Generate CSV with specific columns lscpu -p=CPU,CORE,SOCKET,NODE # Process with specific tools lscpu -p=CPU,CORE | tail -n +5 | sort -t, -k2 -n

Create custom parseable output for specific needs

System Analysis Scripts

CPU topology summary

#!/bin/bash echo "=== CPU Topology Summary ===" echo "Architecture: $(lscpu | grep Architecture | awk '{print $2}')" echo "Total CPUs: $(lscpu | grep "^CPU(s):" | awk '{print $2}')" echo "Sockets: $(lscpu | grep "Socket(s):" | awk '{print $2}')" echo "Cores per socket: $(lscpu | grep "Core(s) per socket:" | awk '{print $4}')" echo "Threads per core: $(lscpu | grep "Thread(s) per core:" | awk '{print $4}')" echo "L3 Cache: $(lscpu | grep "L3 cache:" | awk '{print $3, $4}')"

Create comprehensive CPU topology reports

Performance characteristics

#!/bin/bash echo "=== CPU Performance Info ===" echo "Model: $(lscpu | grep "Model name" | cut -d: -f2 | sed 's/^ *//')" echo "Base Frequency: $(lscpu | grep "CPU MHz" | awk '{print $3}') MHz" echo "Max Frequency: $(lscpu | grep "CPU max MHz" | awk '{print $4}') MHz" echo "Virtualization: $(lscpu | grep Virtualization | awk '{print $2}')" echo "NUMA Nodes: $(lscpu | grep "NUMA node(s):" | awk '{print $3}')"

Extract key performance-related information

Troubleshooting

Common Issues

Missing information

# If some information is missing, check kernel support ls /sys/devices/system/cpu/ # Check if cpufreq information is available ls /sys/devices/system/cpu/cpu0/cpufreq/ # Some features require specific kernel modules lsmod | grep cpufreq

Troubleshoot missing CPU information

Inconsistent frequency information

# Check current frequencies cat /proc/cpuinfo | grep "cpu MHz" # Compare with lscpu lscpu | grep MHz # Check scaling governor cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Understand frequency scaling and reporting differences

Validation

Cross-check with other sources

# Compare CPU count echo "lscpu: $(lscpu | grep "^CPU(s):" | awk '{print $2}')" echo "nproc: $(nproc)" echo "/proc/cpuinfo: $(grep -c processor /proc/cpuinfo)" # Verify topology lscpu -e | tail -n +2 | wc -l ls /sys/devices/system/cpu/cpu* | wc -l

Validate lscpu output against other system sources

Best Practices

CPU Information Best Practices
  • Use Appropriate Format - Choose between human-readable and parseable formats
  • Script Integration - Use parseable format for automated processing
  • Performance Planning - Consider topology for thread affinity and optimization
  • Virtualization - Check virtualization support before VM deployment
  • NUMA Awareness - Consider NUMA topology for memory-intensive applications
  • Regular Monitoring - Include CPU information in system documentation

See also