lscpu Command in Linux
Overview
The lscpu command in Linux is a useful tool that helps you to fetch CPU architecture details of a Linux machine. This command gives you insights into your system's CPU architecture, like the number of CPUs, threads, cores, sockets, and Non-Uniform Memory Access (NUMA) nodes. Furthermore, it also provides details about the CPU family, model, type, and more. Understanding how to use the lscpu command in Linux is essential for both system administrators and users looking to optimize performance or troubleshoot CPU-related issues.
Syntax of lscpu Command in Linux
The basic syntax of the lscpu command in Linux is as follows:
Where:
- lscpu: This is the base command that fetches CPU architecture information.
- [OPTIONS]: The optional parameters or flags that modify the behavior of the lscpu command.
Options in lscpu Command in Linux
-
-h, --help: Display a help message and exit.
For example -
Output:
This is a standard option included in many Linux commands, which gives you a quick way to see the command's usage and options.
-
-p, --parse: Display the information in a format that can be easily parsed by other programs. This will only display active CPUs by default.
For example -
Output:
This is a helpful option for scripts or other programs that need to read the output of lscpu.
-
-e, --extended: Display the CPU information in an extended readable format.
For example -
Output:
This option provides a more comprehensive overview of your CPU architecture.
Example Usages
-
Displaying the CPU architecture details of your machine:
Output:
Explanation: This is the most basic usage of the lscpu command in Linux. It provides a quick and easy way to fetch the CPU architecture details.
-
Displaying only the number of CPUs in your machine:
Output:
Explanation: By piping the output of the lscpu command into the grep command, you can filter out the specific information you need. In this case, the total number of CPUs.
Tips
-
You can combine the lscpu command with grep to easily filter out the exact information you need.
-
Use the --parse option when scripting to get an easily parsable output.
Advanced Use Cases of lscpu Command in Linux
-
Displaying a list of online CPUs only:
Output:
Explanation: The --parse option with specific fields can be used to display detailed information about certain characteristics. In this case, we are displaying online CPUs only.
-
Displaying CPU information in a specific output format:
Output:
Explanation: The -J or --json option is used to display the output in JSON format, which can be useful for scripting and automation.
-
Displaying extended CPU characteristics:
Output:
Explanation: The -e or --extended option can be further refined to display specific characteristics. This can be useful when troubleshooting specific CPU-related issues.
Conclusion
-
The lscpu command in Linux is a powerful tool to get detailed information about your CPU architecture.
-
It comes with a variety of options that allow for easy customization of output, including formats that are useful for scripting and automation.
-
With the help of the grep command, you can easily filter out the information you need.