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?

  • Have you tried indicator-cpufreq? – Android Dev Jan 30 '17 at 17:38
  • Yes I've tried it, but I only get a symbol and when I clock on it, I can choose between "power save" and something else. I don't see any hertz. – Mason Jan 30 '17 at 17:41
  • Would you be good with a bash script? – Android Dev Jan 30 '17 at 18:32
  • @AndroidDev just did that, I've posted a working script as an answer – Mason Jan 30 '17 at 18:58

You may find the following a shorter example:

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:

  • Excellent answer. Was thinking the same thing. The awk power. – Luis Alvarado Jan 30 '17 at 20:42
  • awk is indeed pretty helpful here. And your output is CPU MHz, CPU max MHz and CPU min MHz, my output is the same but the first is CPU-frequentie (MHz) instead of CPU MHz – Mason Jan 30 '17 at 22:05

After some experimentation, I made a script that returns something like 3.12GHz or 2.80GHz. It forces the output to be X.XXGHz.

First, I used a script from this answer.

Then, I made this script:


speed=$(div $(lscpu | grep CPU-frequentie | awk '{print $3;}' | cut -d'.' -f1) 1000 | awk '{print substr($1,2); }' | cut -c -4)

if [ ${#speed} -ge 4 ]; then :
else speed=$speed"0"

echo $speed"GHz"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.