The lscpu command in Linux: processor details

Introduction

In the world of Linux system management, in-depth knowledge of hardware features is essential for optimizing performance, debugging problems and planning updates. One of the most useful commands for obtaining detailed information from the processor islscpu. This tool, part of the util-linux package, legible presents the data that the kernel exposes through the file system/sysand/proc. In this article we will explore what islscpu, how it is invoked, what fields its output shows and how to interpret each one to make the most of your CPU.

What is lscpu and where is it?

The commandlscpucomes from the util-linux project and is available in virtually all modern Linux distributions, such as Ubuntu, Debian, Fedora, CentOS and Arch. It does not require superuser privileges to run, as it only reads read-only information displayed by the kernel. When you call it in a terminal,lscpucollects data from several subdirectories of/sys/devices/system/cpuand forms them in a table readable to humans.

Basic syntax and more common options

The simplest way to use the command is:

lscpu

This will print all available information. However,lscpuoffers several options to filter or customize output:

  • -aor--all: shows information on all logical and physical CPUs, including those that may be off-line.
  • -bor--online: limits the output to the CPUs currently online (the default behavior in many versions).
  • -cor--offline: shows only the CPUs that are off-line.
  • -eor--extended: presents the information in column format, ideal for scripts.
  • -por--parse: generates a comma-separated analysable output, useful for later processing.
  • -sor--sysroot: allows to specify an alternative root directory (useful in chroot or container environments).
  • -hor--help: shows the help and ends.
  • -Vor--version: shows the command version.

Breakdown of the most important fields of the output

Runlscpuwithout arguments produces a list of key-value pairs. The following are the fields most frequently relevant:

  • Architecture:indicates the processor's architecture (e.g. x86 _ 64, aarch64, armv7l).
  • CPU op-mode (s):shows supported operating modes, such as 32-bit, 64-bit or both.
  • Byte Order:the order of the bytes (Little Endian or Big Endian) used by the CPU.
  • CPU (s):total number of logical threads the system sees.
  • On-line CPU (s) list:list of CPUs currently active.
  • Offline CPU (s) list:list of CPUs that are disabled (can be activated later).
  • Thread (s) per core:How many threads are run in each physical core (e.g. 2 for Hyper-Threading technology).
  • Core (s) per socket:number of nuclei present in each physical socket.
  • Socket:amount of CPU sockets installed on the base plate.
  • NOde (s):number of NUMA (Non-Uniform Memory Access) nodes detected.
  • Vendor ID:manufacturer identifier (GenuineIntel, AuthenticAMD, etc.).
  • CPU family:family of processor according to the manufacturer's internal model.
  • Model:model number within the family.
  • Model name:full trade name of the processor (e.g. Intel (R) Xeon (R) CPU E5-2680 v4 @ 2.40GHz).
  • Stepping:internal silicon review.
  • CPU MHz:current clock speed in megahertz (may vary with frequency climbing).
  • CPU max MHz:maximum frequency the processor can reach.
  • CPU min MHz:minimum permitted frequency.
  • BogoMIPS:approximate measurement of performance based on retard loops (not a real benchmark).
  • Virtualization:indicates whether the CPU supports virtualization technologies (VT-x / AMD-V) and whether they are active.
  • L1d cache, L1i cache, L2 cache, L3 cache:data cache sizes, instructions and higher levels.
  • Flags:list of processor capabilities and characteristics (e.g. sse4 _ 2, avx2, aes, vmx).

Examples of practical use

Below are some scenarios wherelscpuis particularly useful:

1. Verify the architecture before installing packages

If you need to know if your system is 64 bits to download the correct binary:

lscpu | grep Architecture

2. Determine the number of threads available to compile with make

Many compilation systems use the variableJOBSbased on the number of logical threads:

export JOBS =$(lscpu -p | grep -v '^ # ' | wc -l)

3. Check if virtualization is enabled

Before creating a virtual machine with KVM or VirtualBox, check the support:

lscpu | grep Virtualization

4. Get information in CSV format for processing with awk or Python

lscpu --parse = CPU, Core, Socket, Node > cpu _ info.csv

5. List only off-line CPUs (useful in energy saving environments)

lscpu --offline

Tips and good practices

  • Remember thatlscpuonly shows what the kernel has detected; if any CPU is disabled at firmware level, it may not appear.
  • In systems with activated hyperthreatening, the number of logical threads (CPU (s)) will be twice the number of physical nuclei.
  • To get a more detailed view of each individual kernel, you can explore directly/sys/devices/system/cpu/cpu*/topologyor uselscpu -e.
  • If you work in containers (Docker, Podman), the command will show the CPU seen from the container, which may be limited by cgroups.
  • Combinelscpuwith other tools likelsmem, lspcianddmidecodeto get a full picture of the hardware.

Conclusion

The commandlscpuis an essential tool for any system manager, developer or Linux enthusiast who needs to know the processor's characteristics in depth. Its legible output, combined with filtering and format options, allows you to quickly obtain critical data for decision-making in performance, software compatibility, update planning and problem cleansing. Dominating its use not only saves time, but also provides a solid basis for optimizing and maximizing the potential of your hardware.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish