lscpu Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
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.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
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.
Turn Learning into Career Growth
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.