lscpu command, short for list CPU, provides a detailed list of information about the CPUs in the system. This includes the CPU number, architecture, vendor, family, model, and CPU caches.
The following text explains the
- A Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
lscpu Command Syntax
lscpu syntax is:
lscpu without invoking arguments produces this output:
In this case, the output details the CPU architecture, cores, threads, CPU family, model, etc. The exact output varies depending on the specific system and its configuration. However, use arguments to filter out the info and get a tailored output.
lscpu Command Options
lscpu command has several arguments that allow users to customize what they see in the output. The following table presents the most important
|Displays the CPU information in human-readable format. Displays only one column of details when used with the column name.
|Optimizes the command output for easy parsing.
|Limits the output to offline CPUs. This option only works with arguments
|Allows the output to only online CPUs (default for
-p). This option only works together with option
|Includes online and offline CPU lines in the output (default for
|Uses hexadecimal masks for CPU sets.
|Uses JSON output format for the default summary or extended output.
|Displays details about CPU caches.
|Shows the sizes in bytes rather than in a human-readable format.
|Prints all available columns. This option only works with either
|Uses subsections in summary output.
|Gathers CPU info for a Linux instance different from the instance from which the
lscpu command is issued.
|Displays physical IDs for all columns with topology elements (core, socket, etc.)
lscpu Command in Linux: Examples
Due to its versatility,
lscpu has plenty of use cases. The following text presents practical
lscpu usage examples.
Example 1: Display CPU Data in Readable Format
To see CPU-related data in a human-readable format, run
lscpu with the
-e argument modifies the output, making it structured and easy to read. The output includes a header line with clear column labels, such as
ONLINE. The data is also aligned under each column, enhancing readability.
-e argument has another function. When run with
lscpu and a column name, it prints human-readable info about the specified column.
The syntax is:
For instance, print only details about the column CPU with:
Example 2: Printing Info in Parsing-Friendly Mode
Run this command:
In the output, values are comma-separated in an easily parsed format. Moreover, each CPU's information is presented in a single line, and the output doesn't include headers or comments.
Example 3: Limiting Output to Online or Offline Mode
lscpu command in Linux provides options to limit its output specifically to online or offline CPUs. This is useful when focusing on the system's active or inactive CPU cores. The relevant options for this purpose are
-b for online CPUs and
-c for offline CPUs.
Note: When using these options, combining them with either
-p is necessary.
For instance, show all online CPUs in human-readable form with:
Next, print offline CPUs in parsing-friendly mode with:
In this case, the output doesn't show any CPUs, as there are no inactive ones.
Example 4: Display Both Online and Offline CPUs
To show both online and offline CPUs, run the
lscpu with the
-a argument only works together with
For instance, print all online and offline CPUs in a human-readable format with:
Example 5: Using Hexadecimal Masks for CPU Sets
lscpu command in Linux, when executed without any options, displays its output in a list format. However, the
-x option allows users to print CPU sets using a hexadecimal mask.
A hexadecimal mask represents processor affinity using hexadecimal (base-16) numbers. It helps users understand how CPU cores are organized and associated with specific tasks or processes.
For instance, enter:
f represents a hexadecimal mask. Each digit in the mask corresponds to a CPU or core. The f in hexadecimal translates to binary as 1111, and in this case, it indicates all CPUs (0 to 3 in this case) are online or part of NUMA node0.
Example 6: Display Output in JSON Format
lscpu command in Linux with the
-J argument generates the output in JSON format. This lightweight data-interchange format is easy for humans to read and write and for machines to parse and generate.
For example, run this command:
This output is useful for scripting or processing CPU details in applications or system management tools that consume JSON data.
Example 7: Finding Specific Info
lscpu command provides details about various CPU-related components. To find specific information, such as the CPUs or sockets number, utilize grep to filter and extract the information from the output.
The syntax is:
lscpu | grep "search-term"
For example, find the number of CPUs with:
lscpu | grep "CPU(s):”
The output indicates the total number of CPUs in the system. The second line provides additional information about the CPUs associated with NUMA node0. The range "0-3" indicates CPUs 0 through share a common memory domain associated with NUMA node0.
The same command works for finding other components. For example, find the number of sockets with:
lscpu | grep "Socket(s):"
The output shows one socket.
Another way to pipe
grep is with this syntax:
lscpu | grep -i 'search_term'
-i makes the search case-insensitive and matches any line in the
lscpu output that includes the
search_term, even if it's part of a larger word.
For instance, run:
lscpu | grep -i 'cpu'
The output is more extensive and includes every cpu instance in the text marked in red.
Example 8: Printing Info about Caches
To view info about caches in an extended readable format, run
lscpu with the
The output details different cache levels (
L3), sizes, associativity, and other relevant parameters.
Example 9: Show Detailed Output About All Available Columns
--output-all argument to display more detailed CPU-related information. It includes additional details such as cache sizes, NUMA information, and extended CPU feature flags.
--output-all argument only works with
For instance, print more details about CPUs in a human-readable format with:
lscpu --output-all -e
After reading this text, you know how to use the
lscpu command and its options. Test our use-case examples to get familiar with the command.
Next, learn how to check Linux CPU usage.