Linux Commands

How to Use Linux lscpu Command Tutorial

The beauty of Linux-like systems is that it provides multiple command-line tools for a single operation. Whether you want to download software/packages or fetch any information from hardware/disk drives of the system, you will get several ways according to your needs while using Linux.

A command-line utility “lscpu” in Linux is used to get CPU information of the system. The “lscpu” command fetches the CPU architecture information from the “sysfs” and /proc/cpuinfo files and displays it in a terminal.

The syntax of the “lscpu” command is mentioned below:

lscpu [options…]

How to use the “lscpu” command in Linux:

Execute the “lscpu” command without invoking any argument in the terminal to display the complete picture of useful information about the processor:

$ lscpu

lscpu Command Options:

The list of several options providing by the “lscpu” command tool is listed below:

To display in Human Readable Format:

In the “lscpu” command, there is an option to display output that is understandable for the user.

Run the “-e” option in the terminal; it will gather CPU related data and display it in Human Readable Format:

$ lscpu –e

Also, if you want to limit the output with the particular column, then use the “-e” option with the column name:

$ lscpu -e=cpu,code

Display in Parsing-friendly Format:

To display the processor information in a parsing-friendly format, use the “-p” option:

$ lscpu –p

Hexadecimal Masks for CPU Sets:

When we execute the “lscpu” command, it displays output in list format by default, but you can use the hexadecimal mask to print CPU sets using the “-x” option:

$ lscpu –x

Display in JSON Format:

The “lscpu” command also allows to print the extended output of CPU information in JSON format through the “-J” option:

$ lscpu –J

Offline and Online CPU list:

The output can also be limited with the summary of the online and offline CPU list by using the “-e” and “-p” options:

  1. The “-b” flag for the list of online CPUs.
  2. The “-c” flag for the list of offline CPUs.

These flags will run only with the execution of “-e” and “-p” options.

Such as, if you want to print the results only for online CPUs, run the given command in a terminal:

$ lscpu -e –b

Display Help:

To print a help message regarding the “lscpu” command and its options, use the “-h” option:

$ lscpu -h

Display Version:

Run the “-V” option in a terminal to print version of the “lscpu” command tool:

$ lscpu -V

Conclusion:

The “lscpu” command is a Linux tool used to fetch CPU-related information from the sysfs files and display the output in the terminal.

This guide has discussed the “lscpu” command tool and its usage with multiple functions.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.