Linux Commands

How to Get CPU Info in Linux

The CPU is known as the brain of a computer system since the entire operating system relies on it. As time goes by, it becomes necessary to check the details of the CPU to improve performance and address any issues that may arise. It is not difficult to find the real-time CPU information and check how much load is handled by it in Linux.

How to Get CPU Info in Linux

Fortunately, Linux offers numerous methods to accomplish any given task, which provides users with a great deal of flexibility. Similarly, if we want to fetch CPU details, multiple command-line tools are available for this purpose.

Let’s go through the various methods to display CPU information on a Linux system.

(I am going to perform this tutorial on the Ubuntu 22.04 machine).

1. Get CPU Info Using lscpu Command

The lscpu command is a utility that retrieves CPU details from sysfs and /proc/cpuinfo files, displaying the results on the Linux terminal.

Just type the lscpu on the terminal and get the CPU details:

lscpu

By using the lscpu command tool, you would get the complete picture of CPU data. However, reading these details can be complex. To get a specific or required amount of details like processor, threads, model, or number of cores, the grep command is the best choice.

The Linux grep command tool allows users to find and print specified strings on the Linux terminal. To get detailed information about particular queries, use the combination of the grep and lscpu commands. Make sure to provide the exact name of the queries you need details for.

Let’s suppose I need to find details of my processor model name, cores, threads, CPU family, and NUMA, the command would be:

lscpu |egrep 'Model name|Core|Thread|CPU family|NUMA|CPU/ (s/)'

2. Get CPU Info Using /proc/cpuinfo File

All Linux distributions come with a file called /proc/cpuinfo, which contains detailed information about the CPU architecture in use. To view this information, we can utilize the cat or less command to print the contents of the /proc/cpuinfo file in the terminal.

Run the given command with the /proc/cpuinfo file to get the desired results:

cat /proc/cpuinfo

less /proc/cpuinfo

3. Get CPU Info Using cpuid Command

If you’re working in an x86 CPU processor, the Linux cpuid command-line utility is the best choice to find the detailed CPU(s) queries that aren’t available in the lshw or /proc/cpuinfo.

The cpuid command tool is not pre-installed in Linux systems; however, you can get it by installing through the package manager.

Execute the mentioned command in the terminal to start installing cpuid command tool:

sudo apt install cpuid

Now, simply type the cpuid without passing any argument, and it will display the complete details of the x86 CPU:

cpuid

4. Get the CPU Info Using nrpoc Command Tool

To find out only the quantity of cores processors present in a Linux system, just type the nproc command in the terminal and you will find the number of cores in the output:

nproc

5. Get the CPU Info Using top & htop Command

The top and htop commands are useful for monitoring system performance, including the processor. The htop is the newer version of the top command, offering an interesting and interactive interface for a better understanding of users.

Let’s run both of the commands i-e., top, and htop individually to see the difference:

top

The htop command tool is not preinstalled in some of the Linux tools, however, you can get it using the apt or snap package manager:

Run the given command in the terminal to install the htop tool on a Linux machine:

sudo apt install htop

Now, type the htop in the terminal to see the results:

htop

6. Get CPU Info Using hwinfo Command

As the name describes, the hwinfo command tool is used to display hardware-related details on the terminal. To install the hwinfo utility on the terminal, run the given apt command:

sudo apt install hwinfo

Now, type the hwinfo to display hardware details on the terminal:

hwinfo --short

7. Get CPU Info Using dmidecode Command

The dmidecode command in Linux is used to retrieve system hardware data like processor, BIOS, RAM, serial number, and displays it in a human-readable format.

Run the mentioned command to see how the dmidecode command works in a Linux terminal:

sudo dmidecode -t processor

8. Get CPU Info Using inxi Command

The inxi command-line utility is another way to print necessary details about the CPU on the screen. To use this tool, first, we need to install it using the apt package manager as mentioned below:

sudo apt install inxi

Now, run the inxi command with the -C parameter to show the CPU details:

inxi -C

9. Get the CPU Info Using lshw Command

The lshw is the light-weighted command-line utility used to extract hardware configuration details and generate brief reports on it. Run the lshw command tool with the -C argument to fetch CPU processing details:

sudo lshw -C CPU

10. Get CPU Info Using hardinfo Tool

The hardinfo tool is a popular diagnostic tool for hardware components. This user-friendly tool presents a graphical display that helps to find system hardware details.

To see how hardinfo tool works, we need to install it:

sudo apt install hardinfo

Once you completed the successful installation of hardinfo graphical tool on a Linux machine, type hardinfo in the terminal to display its screen:

hardinfo

Conclusion

As we all know the importance of CPU because the whole system depends on it and it is responsible for the overall performance as well. To keep the system compatible and reliable, it is now necessary to monitor the load and processing details regularly to troubleshoot issues that may arise. This guide has mentioned the multiple command-line tools to display the CPU information on a Linux screen. Some of these tools are pre-installed while some can be installed using our given commands.

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.