10 Useful Commands to Get CPU Information on Linux

One of the key components that dictate the overall performance of a system is the Central Processing Unit (CPU). Keeping track of CPU performance and utilization, a key component of system monitoring, helps with early detection of potential issues.

In this post I will go over 11 different Linux commands to get cpu information. Having a good grasp of these commands is essential for system administrators, developers, and power users alike.

Linux Commands to Get CPU Information

Understanding the specifications and capabilities of your CPU is crucial for optimizing your system’s performance. Using the commands shown in this section with help you gather essential information about your CPU, such as its make, model, number of cores, and cache size. In this section, I will go over two options to get CPU information.

1. ProcFS: Use cat Command To get CPU Information

Process File System (ProcFs), is a virtual file system used in Linux based operating systems to provide a view of the kernel and running processes as a file hierarchy. It allows users and system administrators to access information about the state of the system, such as running processes, system memory usage, CPU usage, and network statistics, as though they were files.

To get CPU information use the following command:

user@slap:~$ cat /proc/cpuinfo

You will see output similar to what is shown below.

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 141
model name      : 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2304.001
cache size      : 24576 KB
physical id     : 0
siblings        : 16
core id         : 0
cpu cores       : 8
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 21
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm avx512_vp2intersect flush_l1d arch_capabilities
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs
bogomips        : 4608.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

Note: The output shows all CPU cores as separate CPUs. If your system has a 6-core CPU then you will see 6 similar entries.

The output includes:

  • Processor: The logical processor number
  • Vendor ID: The manufacturer of the CPU, like GenuineIntel or AuthenticAMD
  • Model name: The make and model of the CPU
  • CPU MHz: The current CPU frequency in MHz
  • Cache size: The size of the CPU cache
  • Flags: The supported CPU features, such as SSE, AVX, or virtualization

You can use grep to filter out only the information you want to see. For example, if you want to find out about the CPU bugs associated with the CPU then use the following command:

user@slap:~$ cat /proc/cpuinfo | grep 'vendor' | uniq
vendor_id       : GenuineIntel

Note: Since I am on a multi-core machine, which will be the case for most of you, I have used the uniq command to show only a single line with no repetition.

2. lscpu: Get CPU Architecture Information

The lscpu command, provides similar information when compared to the cat command on /proc/cpuinfo, but in a more user-friendly format.

To view the CPU information use the command:

user@slap:~$ lscpu

Following is the output.

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  16
  On-line CPU(s) list:   0-15
Vendor ID:               GenuineIntel
  Model name:            11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    CPU family:          6
    Model:               141
    Thread(s) per core:  2
    Core(s) per socket:  8
    Socket(s):           1
    Stepping:            1
    BogoMIPS:            4608.00
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rd
                         tscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 m
                         ovbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced
                         fsgsbase bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512b
                         w avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_
                         vpopcntdq rdpid fsrm avx512_vp2intersect flush_l1d arch_capabilities
Virtualization features:
  Hypervisor vendor:     Microsoft
  Virtualization type:   full
Caches (sum of all):
  L1d:                   384 KiB (8 instances)
  L1i:                   256 KiB (8 instances)
  L2:                    10 MiB (8 instances)
  L3:                    24 MiB (1 instance)
Vulnerabilities:
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
  Srbds:                 Not affected
  Tsx async abort:       Not affected

lscpu command provides output in a readable tabular format. The output includes details such as:

  • Architecture: The processor’s architecture, like x86_64 or arm64
  • CPU(s): The total number of CPU cores
  • Thread(s) per core: The number of threads per core
  • Core(s) per socket: The number of cores per CPU socket
  • Model name: The make and model of the CPU
  • Cache sizes: The sizes of L1, L2, and L3 caches.

CPU Performance Monitoring Commands

Earlier I showed you how to get the CPU information. In this section, I will go over commands to monitor your CPU’s performance.By keeping track of CPU usage and load, you can identify resource-hungry processes and address potential bottlenecks.

In this section, I will discuss three important CPU performance monitoring commands.

3. top: Get System and Process Information

The top command provides a real-time, dynamic view of the processes running on a system. It displays information about the system’s CPU usage, memory consumption, and other critical performance metrics.

To run the command enter the following in a terminal:

user@slap:~$ top -d 1

The following output is shown:

top - 16:19:35 up  2:59,  0 users,  load average: 0.00, 0.00, 0.00
Tasks:   5 total,   1 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  25415.3 total,  25075.2 free,    126.5 used,    213.6 buff/cache
MiB Swap:   7168.0 total,   7168.0 free,      0.0 used.  24969.0 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    1 root      20   0     908    536    472 S   0.0   0.0   0:00.03 init
    9 root      20   0     908     84     20 S   0.0   0.0   0:00.00 init
   10 root      20   0     908     84     20 S   0.0   0.0   0:00.20 init
   11 sohail    20   0    9304   5448   3544 S   0.0   0.0   0:00.43 bash
  254 sohail    20   0   10764   3776   3172 R   0.0   0.0   0:00.00 top

Note: I used the option “-d 1”, which updates the numbers every second.

Top displays various information about your system’s CPU usage, including:

  • %Cpu(s): Show the total usage of the CPU. It averages all the core usages to display as a single number
  • MiB: There are two lines in the output. The shows the usage of the physical memory and the next line shows the swap space usage.
  • %CPU: The percentage of CPU usage per process.
  • %MEM: The percentage of memory usage per process.

4. htop: An enhanced ‘top’

The htop command is an enhanced version of top, offering a more user-friendly and interactive interface for monitoring system performance. It provides a color-coded representation of CPU usage and supports additional features like scrolling and process filtering.

user@slap:~$ htop

Here is the output.

htop Command output on Linux

While both top and htop provide real-time CPU performance monitoring, htop offers additional features and a more intuitive interface.

5. uptime: Get Information About CPU Load Averages

Finally, I want to list the command uptime, that provides information on how long a system has been running. The uptime command also provides information about the 1, 5, and 15-minute CPU load average of the system.

To run the command simply enter it on the command line.

user@slap:~$ uptime

The output is:

 16:50:32 up  3:30,  0 users,  load average: 0.10, 0.06, 0.01

Output in this case shows that the system has been up for 3 hours and 30 minutes.

Advanced CPU Information and Diagnostic Commands

For power users, developers, and system administrators, having access to advanced CPU information and diagnostic tools is crucial for optimizing system performance and troubleshooting potential issues.

In this section, we will discuss three advanced commands for obtaining detailed CPU and diagnostics information.

6. cpuid: Get CPU Information Using Processor CPUID Command

cpuid is a powerful command that displays detailed information about your CPU by directly querying the processor’s built-in CPUID instruction. This command provides more in-depth information than lscpu or cat /proc/cpuinfo, including processor features, cache and TLB (Translation Lookaside Buffer) configurations, and supported instruction sets.

Since this command is not installed by default on Linux systems, I will have to manually install it. Use the following instructions to install it on Debian based systems.

sohail@slap:~$ sudo apt install cpuid

To run the command enter the following in terminal window.

sohail@slap:~$ cpuid

Output is shown below.

CPU 0:
   vendor_id = "GenuineIntel"
   version information (1/eax):
      processor type  = primary processor (0)
      family          = 0x6 (6)
      model           = 0xd (13)
      stepping id     = 0x1 (1)
      extended family = 0x0 (0)
      extended model  = 0x8 (8)
      (family synth)  = 0x6 (6)
      (model synth)   = 0x8d (141)
      (simple synth)  = Intel Core (Tiger Lake R0) [Willow Cove] {Sunny Cove}, 10nm++
   miscellaneous (1/ebx):
      process local APIC physical ID = 0x0 (0)
      maximum IDs for CPUs in pkg    = 0x10 (16)
      CLFLUSH line size              = 0x8 (8)
      brand index                    = 0x0 (0)
   brand id = 0x00 (0): unknown
   feature information (1/edx):
      x87 FPU on chip                        = true
      VME: virtual-8086 mode enhancement     = true
      DE: debugging extensions               = true
      PSE: page size extensions              = true
      TSC: time stamp counter                = true
      RDMSR and WRMSR support                = true
      PAE: physical address extensions       = true
      MCE: machine check exception           = true
------- TRUNCATED THE REST OF THE OUTPUT --------

Note: The output of this command is about 700 lines for each one of my CPU cores, so I have removed rest of the lines.

The cpuid command produces an extensive output with detailed information about your CPU. This command is for users who want to go beyond just finding out the load on their system.

7. inxi: Command Line System Information Script

inxi is another tool that provides comprehensive information about system hardware, configuration, and software environment.

Similar to many other commands, inxi also extracts information from various sources, such as /proc, sysfs, and other system utilities.

First, install the inxi package.

sudo apt install inxi

To get basic system information you can run the command by itself as shown below.

root@slap:~# inxi

CPU: 8-core 11th Gen Intel Core i7-11800H (-MT MCP-) speed: 2304 MHz
Kernel: 5.10.102.1-microsoft-standard-WSL2 x86_64 Up: 2h 42m Mem: 489.1/25415.3 MiB (1.9%)
Storage: 512 GiB (47.5% used) Procs: 10 Shell: Bash inxi: 3.3.13

The inxi command supports various options and parameters to display specific information about your system:

  • inxi -C: Displays information about the CPU
  • inxi -M: Displays information about the motherboard
  • inxi -D: Displays information about the hard drives
  • inxi -C: Displays information about network interfaces
  • inxi -C: Displays information about graphics cards

For a full list of inxi options check the man page.

8. lshw: List Linux Hardware Information

The lshw command, short for list hardware, provides detailed information about a computer system’s hardware components. Extracting information from various sources, the lshw command can display details about the CPU, memory, storage devices, network interfaces, and other hardware components.

Check the lshw man page for details on available options.

To get more comprehensive information, run the lshw command with root privileges.

Run the lshw command with the -class cpu options to get information about the CPU only.

root@slap:~# lshw

Shown below is the truncated output with CPU info.

  *-cpu
       product: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
       vendor: Intel Corp.
       physical id: 1
       bus info: cpu@0
       version: 6.141.1
       width: 64 bits
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp x86-64 constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm avx512_vp2intersect flush_l1d arch_capabilities
       configuration: microcode=4294967295

Check my post on Useful Command to Collect Hardware and System Information, where I go over additional lshw options.

CPU Temperature and Power Management Commands

Ensuring proper temperature management and power usage is essential for maintaining your system’s stability and prolonging the life of your hardware. Overheating or excessive power consumption can lead to performance degradation or even damage to your CPU.

In this section, I will go over two commands for monitoring CPU temperature and power management in Linux.

9. cpufreq-info: Utility to Retrieve cpufreq Kernel Information

The command cpufreq-info provides information about your CPU’s frequency scaling capabilities and power management settings. It displays the current CPU frequency, available governors, and other power-related information.

This command is part of the package cpufrequtils, which also includes another command cpufreq-set, that you can use to modify CPU frequency settings.

to install the package on Linux use the following command:

user@slap:~$ sudo apt install cpufrequtils

Below is cpufreq-info output example:

root@slap:~# sudo cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to [email protected], please.
analyzing CPU 0:
  no or unknown cpufreq driver is active on this CPU
  maximum transition latency: 4294.55 ms.
analyzing CPU 1:
  no or unknown cpufreq driver is active on this CPU
  maximum transition latency: 4294.55 ms.

Do note that the cpufrequtils package has not been updated for over 10 years now.

The sensors command allows you to monitor the temperature, voltage, and fan speeds of your CPU and other hardware components. It retrieves data from the hardware monitoring chips present on the motherboard.

This command is not available by default and you will have to install it. Use the following to install on Linux.

user@slap:~$ sudo apt install lm-sensors

Once installed run the command sensors-detect to initialize.

user@slap:$ sudo sensors-detect

The script will go through an initialization process and will ask for input for detecting various sensor types. Enter YES to the options that you want to have monitored.

sensors-detect Command

Once the sensors are initialized you can run the sensors command to start monitoring. Check the man page for sensors for details of available options.

I am going to run sensors command along with the watch command to execute it repeatedly.

user@slap:$ watch 'sensors | grep "Core "'

Output is :

Core 0: +56.0C (high = +82.0C, crit = +100.0C)
Core 1: +55.0C (high = +82.0C, crit = +100.0C)

Note: The number of cores you see will depend on the CPU being used.

By regularly monitoring your CPU temperature and fan speeds, you can ensure optimal cooling and prevent overheating.

Summary

In this post, I went over available command line utilities to get information about CPU and various CPU utilization statistics on Linux.

By using these commands, you can maintain a stable and efficient system, address potential issues proactively, and optimize your system for different workloads and applications.

If you liked this list then also check post on 12 Commands to Monitor Hardware and System Information on Linux.