How to use the command lscpu (with examples)

How to use the command lscpu (with examples)

lscpu is a command in Linux that displays information about the CPU architecture. It provides detailed information about the CPU, such as the number of CPUs, cores per socket, threads per core, architecture, vendor ID, model name, etc. It is a useful command for system administrators, developers, or anyone who wants to gather information about the CPU.

Use case 1: Display information about all CPUs

Code:

lscpu

Motivation: The motivation for using this example is to get an overview of the CPU’s architecture and specifications. It provides information such as the number of CPUs, cores per socket, threads per core, architecture, vendor ID, model name, etc. This information can be useful for system administrators to understand the hardware configuration of the system.

Explanation: The command lscpu without any arguments displays information about all CPUs in a concise format. It provides details such as CPU architecture, vendor ID, model name, number of sockets, cores per socket, threads per core, etc.

Example output:

Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  2
...

Use case 2: Display information in a table

Code:

lscpu --extended

Motivation: The motivation for using this example is to display the CPU information in a tabular format, which makes it easier to read and interpret. This format is particularly useful when analyzing multiple CPUs or comparing different systems.

Explanation: The --extended option in the lscpu command is used to display information in a table format. This option provides a tabular view of all the CPU information, including both the concise and extended details.

Example output:

CPU
+-----------------------------------------------------------------------+
|Extended CPU Model Name     |CPU Family    |Architecture |Model          |
+-----------------------------------------------------------------------+
|Intel(R) Core(TM) i5-7300HQ |6             |6            |158            |
|Intel(R) Core(TM) i5-7300U  |6             |6            |142            |
+-----------------------------------------------------------------------+

Use case 3: Display only information about offline CPUs in a table

Code:

lscpu --extended --offline

Motivation: The motivation for using this example is to specifically view information about offline CPUs. This could be useful in scenarios where troubleshooting or analyzing CPU resources is required.

Explanation: The --offline option in the lscpu command is used to display information only about offline CPUs. When this option is used along with --extended, it provides a table view of the concise and extended details of offline CPUs.

Example output:

CPU
+-----------------------------------------------------------+
|Extended CPU Model Name |CPU Family |Architecture|Model     |
+-----------------------------------------------------------+
|Intel(R) Xeon(R) E5-2699 |6          |9           |85        |
+-----------------------------------------------------------+

Conclusion:

The lscpu command is a powerful tool to gather information about the CPU architecture in Linux. It provides various options to display CPU information in different formats, including concise, table, and offline CPUs. By using the examples provided, users can easily obtain details about the CPU, such as vendor ID, model name, number of cores, etc., which can be useful for system administrators, developers, or anyone interested in understanding the hardware configuration of their system.

Related Posts

How to use the command `mpg321` (with examples)

How to use the command `mpg321` (with examples)

mpg321 is a high-performance MPEG 1.0/2.0/2.5 audio player for Layer 1, 2, and 3.

Read More
How to use the command 'e4defrag' (with examples)

How to use the command 'e4defrag' (with examples)

The ’e4defrag’ command is designed to defragment an ext4 filesystem. Defragmentation is the process of rearranging the data on a filesystem to optimize performance and improve disk space utilization.

Read More
How to use the command 'archey' (with examples)

How to use the command 'archey' (with examples)

The ‘archey’ command is a simple tool for stylishly displaying system information.

Read More