The CPU Information in any machine includes information about the processor, the vendor details, model name, architecture, speed of processing, etc. In Linux, CPU information is stored in a system file, which can be either read using a text editor, or it can be read and used in an administrative shell script.
Open the file /proc/cpuinfo using a text editor of your choice.
$ vim /proc/cpuinfo
As you can see in the screenshot above, all the information like the model name, speed, cache size, is present in the file. You can also view the contents of this file directly on the command line by running:
$ less /proc/cpuinfo
This will output the contents on the command line, and you can press ‘Enter’ to scroll down. Apart from reading this file, there are few inbuilt commands which you can run to get the CPU information.
Command lscpu
First, let us check out the simple command ‘lscpu’ which prints the information in a neat and more readable format.
$ lscpu
This command has some useful options as well. For example, you can output the data in ‘JSON’ format using the option '-J'
.
$ lscpu -J
You can also save this output to a file by simply redirecting the output.
$ lscpu > cpuinfo.txt
Command lshw
The lshw stands for ‘list hardware‘ and it’s a command to get information about all the hardware used by the Linux system. We can use this command with the argument '-c CPU'
to get a short output containing information about the CPU.
$ sudo lshw -c CPU
Note that even though we are just reading the information, this command is recommended to be run as super-user, i.e. using sudo. There is less information in this output than ‘lscpu‘ and the list of ‘capabilities‘ is the same as the ‘flags‘ listed in the output of lscpu.
Conclusion
In this article, we have seen how to check the CPU information in a Linux system. There are obviously many more commands to get the CPU info, some of which are not available by default and need to be installed separately.
Thanks for reading! If you know any more cool commands to check CPU info, let us know in the comments!