The lscpu command in Linux is a useful utility that provides detailed information about the system’s CPU architecture. When executed, it displays data such as the number of CPUs, threads, cores, and sockets and information about the CPU vendor, model, speed, and cache sizes. This command gathers information from various system files, including /proc/cpuinfo, and presents it in human-readable form. It is particularly valuable for system administrators and developers who need to assess or optimize system performance based on the underlying hardware.

But before we do that, it’s worth mentioning that all examples in this tutorial have been tested on Ubuntu 24.04 LTS.

Linux lscpu command

The lscpu command in Linux displays information about the CPU architecture.  Here’s the syntax of the tool:

lscpu [-a|-b|-c] [-x] [-s directory] [-e[=list]|-p[=list]]

lscpu -h|-V

And here’s what the man page says about it:

       lscpu  gathers  CPU  architecture  information from sysfs and /proc/cpuinfo.  The command 

output can be optimized for parsing or for easy readability by humans.  The information

includes, for example, the number of CPUs, threads,  cores,  sockets,  and  Non-Uniform

       Memory  Access (NUMA) nodes. There is also information about the CPU caches and cache

sharing, family, model, bogoMIPS, byte order, and stepping.

       Options that result in an output table have a list argument. Use this argument to customize

the command output. Specify a comma separated list of column labels to limit the output

table to only the specified columns, arranged in the specified order. See COLUMNS for a

list of valid column labels. The column labels are not case sensitive.

       Not all columns are supported on all architectures. If an unsupported column is specified,

lscpu prints the column but does not provide any data for it.

The following Q&A-styled examples should give you a better idea on how this tool works.

Q1. How to use lscpu command?

Basic usage is pretty straight forward – all you have to do is to run the ‘lscpu’ command sans any options.

lscpu

<img alt="How to use lscpu command" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/08/echo/lscpu.png66cb36f755a7e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="550" loading="lazy" src="data:image/svg xml,” width=”462″>

Q2. How to make lscpu display information in a human-readable format?

A specific command line option -e – lets you do this.

lscpu -e

For example, here’s what the command above produced in output:

<img alt="How to make lscpu display information in human readable format" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/08/echo/lscpu-e.png66cb36f791117.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="97" loading="lazy" src="data:image/svg xml,” width=”500″>

If you want, you can also limit the output to specific columns. For example, the following command limits the output to CPU and NODE columns.

lscpu -e=cpu,node

<img alt="lscpu command formatted result" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/08/echo/lscpu-e-list.png66cb36f7c0e20.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="100" loading="lazy" src="data:image/svg xml,” width=”310″>

Q3. How can the output be limited to only online or offline CPUs?

The lscpu command lets you limit its output to only online or offline CPUs. You can do this using the -b and -c command line options.

lscpu -b
lscpu -c

Note that both these command line options may only be specified together with option -e or -p.

Q4. How do you make lscpu display output in parsing-friendly format?

You can do this using the -p command line option.

lscpu -p

Following is the output this command produced in my case:

<img alt="How to make lscpu display output in parsing-friendly format" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/08/echo/lscpu-p.png66cb36f80bbed.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="131" loading="lazy" src="data:image/svg xml,” width=”500″>

Note that just like in the case of -e option, you can also limit the output in this case by passing the ‘list’ argument.

–parse[=list]

Here’s what the man page has to say about the ‘list’ argument:

If the list argument is omitted, the command output is compatible with earlier versions of lscpu. 

In this compatible format, two commas are used to separate CPU cache columns. If no CPU caches are

identified the cache column is omitted.

If the list argument is used, cache columns are separated with a colon (:). When specifying the

list argument, the string of option, equal sign (=), and list must not contain any blanks or other

whitespace. Examples: '-p=cpu,node' or '--parse=cpu,node'.

Q5. How to make lscpu use hexadecimal masks for CPU sets?

By default, lscpu prints CPU sets in list format (for example, 0,1). However, you can have lscpu use hexadecimal masks for CPU sets, using the -x command line option.

lscpu -x

<img alt="How to make lscpu use hexadecimal masks for CPU sets" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/08/echo/lscpu-x.png66cb36f85190d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="221" loading="lazy" src="data:image/svg xml,” width=”352″>

Conclusion

Like lshw, the lscpu command is not something that you’ll require every day, but it may save your day when the need arises. In this tutorial, we have discussed the majority of its features (command-line options), so practice these, and when you’re done, head to the tool’s man page to learn more.