Skip to content

Instantly share code, notes, and snippets.

@amitkhare
Last active May 25, 2025 07:03
Show Gist options
  • Save amitkhare/a4e5eebfa629b9fc2c18cbf3fce60f3c to your computer and use it in GitHub Desktop.
Save amitkhare/a4e5eebfa629b9fc2c18cbf3fce60f3c to your computer and use it in GitHub Desktop.
Getting CPU tempature on Ubuntu/ Raspberry Pi

Create a file

$ sudo nano /usr/local/bin/cpu-temp

Paste content

#!/bin/bash

temp=$(</sys/class/thermal/thermal_zone0/temp)

while true
do
 temp=$(</sys/class/thermal/thermal_zone0/temp)
 temp_f=`echo  "$temp/1000" | bc -l`
 printf  "CPU Temp: %.3f C\r\e\e[?25l"  $temp_f
 sleep 1
done

Save and Exit

CTRL+S then CTRL+X

Run from anwhare in the terminal

$ cpu-temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment