How to Get CPU Speed as *.** GHz – System Monitoring Guide

cpufreqmonitoringoutputsystem-tray

I currently use indicator-sysmonitor to see my CPU and RAM percentage in my system tray. But I would like to add my CPU speed. Now I know there are multiple commands (e.g. lscpu | grep "CPU-frequentie" (Dutch) ) to get the CPU speed but I want in a way like this: 2.85 GHz.

How do I alter an output like 2850.153 to something like the 2.85 GHz?

Best Answer

You may find the following a shorter example:

#!/bin/sh
lscpu |awk -F : '($1=="CPU MHz") {printf "%3.2fGHz\n", $2/1000}'

Note that, on my system, using an AMD CPU and lscpu version 2.27.1 on ubuntu server 16.04 (64 bit) I have lines in the output as follows:

CPU MHz:               4000.000
CPU max MHz:           4000.0000
CPU min MHz:           1400.0000

The awk command uses ":" as the field separator. It looks for the line starting "CPU MHz" and then simply prints the value over 1000 (convert MHz to GHz) using 3.2 format -- three significant figures with two decimal places.

From your question, you appear to be looking for "CPU-frequentie" is the lscpu output. I don't know what the output of your lscpu looks like, but I assume that you might need to substitute "CPU-frequentie" for "CPU MHz" in the awk line

For completeness, the output I get on my system is:

4.00GHz
Related Question