Getty Images/iStockphoto

Tip

Useful commands to check CPU info in Linux systems

You can issue commands through your Linux CLI to gather CPU information, including detailed information on cores, class, virtualization support, architecture and usage.

To troubleshoot or build a software stack, you must know what type of architecture you work with, as well as the details about the hardware and its performance. When it comes to Linux, you can gather that information via the command-line interface. The Linux CLI provides detailed CPU information, such as the number of CPU cores, CPU architecture and CPU usage.

Several commands pull CPU information from hardware, regardless of bare-metal or virtualized hardware use. These commands work on any Linux distribution and come preinstalled on systems.

Checking CPU in Linux

The lscpu command displays a considerable amount of general CPU information.

When you run the lscpu command without any arguments, it returns a large amount of information -- more information than necessary for basic information. Fortunately, you can weed out some of that information by implementing additional arguments.

For example, if you only want information about the CPU make and model, number of sockets, number of CPU cores, threads per core and total threads, you can pipe the lscpu command to grep.

More information than required will come from the lscpu command.
The lscpu command returns more information than you usually require.
lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU/(s/)'

The output then becomes easier to read and use.

lscpu output piped through grep.
The output of lscpu piped through grep

With this information, you can see what types of applications and services can run on a machine.

How to find out if a CPU supports virtualization

If you intend to use a system for virtualization, you must know whether the CPU can support virtualization technology. You can use the lscpu command to find this. Once again, pipe it through grep, but this time, have it check for the Virtualization flag with the command lscpu | grep 'Virtualization'.

If the output lists VT-x, then that CPU is enabled for virtualization. If VT-x is not listed, you must use a different machine.

How to check CPU hardware class information

To get detailed, in-depth information on the CPU class, use sudo privileges with the lshw command:

sudo lshw -C CPU

The output of the above command should give you more in-depth detail about the CPU, including the slot type, size, capacity, width, clock speed, vendor and ID.

lscpu output piped through grep.
The output of lscpu piped through grep

How to get even more detailed information

To gather as much detailed information about the CPU as possible, read out the contents of the cpuinfo file with the command cat /proc/cpuinfo.

A significant amount of information appears, which requires you to page through. If the terminal doesn't scroll, pipe this command through less:

cat /proc/cpuinfo | less
Output of cat /proc/cpuinfo can be overwhelming without arguments.
Similar to lscpu, the output of cat /proc/cpuinfo can be overwhelming without any arguments.

The output from cpuinfo includes sections for every CPU in the system. For example, a system with 16 CPUs lists information for CPUs 0-15.

How to check CPU usage

Check how the CPU is being used with the htop command. This command prints out real-time information, including tasks, threads, load average uptime and usage for each CPU.

To run this tool, issue the command htop.

A real-time display appears with information on how the CPU is being put to use.

View real-time statistics with htop.
Using htop to view real-time statistics for system CPUs

To learn more about a specific command, read the man page -- such as man htop or man lscpu -- for that command.

Additional commands to find CPU info in Linux

There are additional Linux commands that are helpful in digging up information about a CPU. Let's take a look at some of them.

nproc

This command is helpful when the system seems overloaded. To list the number of processing units available, issue the command nproc.

On my AMD Ryzen system, the output is 24. This does not represent the number of physical CPUs. Instead, it calculates the value with the following formula: Threads per core multiplied by cores per socket multiplied by sockets.

You can use nproc in the following ways:

  • To print total installed processing units, use the command nproc --all.
  • To exclude N processing units, where N is a value, use the command nproc --ignore=N.

dmidecode

The dmidecode command dumps the computer's Desktop Management Interface (DMI) or System Management BIOS table into a human-readable form. This command prints information for BIOS, system, motherboard, chassis, cache and CPU. Sudo privileges are necessary to use dmidecode.

The command is run as sudo dmidecode.

Pipe the command through grep like this

sudo dmidecode | grep Processor

The above command limits the output to lines that contain the string Processor.

inxi

This command is one of few that's not installed on Linux distributions by default. Install this app from the standard repositories on your distribution, such as sudo apt-get install inxi -y for Ubuntu/Debian-based distributions. Install epel-release first if you're using a Fedora-based distribution.

The inxi command lists information about the Linux system, such as the following:

  • CPU make and model.
  • CPU speed, min and max.
  • Kernel version.
  • Uptime.
  • Memory.
  • Storage.
  • Number of running processes.
  • Shell.
  • The inxi version.

Get even more details about the system, such as motherboard Unified Extensible Firmware Interface version, GPU display resolution and network devices, by adding the -b flag to the command, like inxi -b.

For detailed CPU information, issue the command inxi -C.

That includes information about L2 cache and core speeds -- for each core.

cpuid

This command dumps details about the x86 CPU, gathered from the CPUID instruction, and determines the exact CPU from that information. The cpuid command prints out vendor_id, version, feature and miscellaneous information.

The command is cupid and isn't installed by default but can be added from standard repositories, such as the following:

sudo apt-get install cpuid -y or sudo dnf install cpuid -y

This prints out more information than necessary, but it gives you a good sense of the CPU installed on your machine.

Jack Wallen is an award-winning writer and avid promoter and user of the Linux OS.

Next Steps

Everything you need to know about Linux man pages

Dig Deeper on Data center ops, monitoring and management

SearchWindowsServer
Cloud Computing
Storage
Sustainability
and ESG
Close