How to Check CPU Temperature in Linux
Most modern systems have thermal sensors built into the CPU and motherboard. Reading these sensors is essential for monitoring system health, diagnosing performance issues, and preventing thermal throttling or hardware damage.
Install lm-sensors
The standard tool for reading hardware sensors on Linux is lm-sensors. Install it on your system:
Debian/Ubuntu:
sudo apt install lm-sensors
RHEL/CentOS/Fedora:
sudo dnf install lm_sensors
Arch:
sudo pacman -S lm_sensors
After installation, run the sensor detection:
sudo sensors-detect
This interactive script probes your hardware and configures the kernel modules needed to read sensors. Answer yes to most prompts to enable detection of all available sensors.
Reading CPU Temperature
Once configured, use the sensors command to display all detected temperatures:
sensors
You’ll see output like this:
coretemp-isa-0000
Adapter: ISA adapter
Core 0: +52.0°C (high = +100.0°C, crit = +100.0°C)
Core 1: +48.0°C (high = +100.0°C, crit = +100.0°C)
Core 2: +50.0°C (high = +100.0°C, crit = +100.0°C)
Core 3: +49.0°C (high = +100.0°C, crit = +100.0°C)
Extract Specific Core Temperature
If you need to extract a single core’s temperature programmatically, use sensors -u for uniform output:
sensors -u | grep "Core 0" | grep "input" | awk '{print $2}'
For a cleaner approach with better parsing:
sensors -A -u coretemp-isa-0000 | awk '/Core 0:/{getline; print $2}'
Or using grep and cut:
sensors | grep "Core 0" | awk '{print $3}' | tr -d '°C'
Get Average CPU Temperature
To get the average temperature across all cores:
sensors -A -u | grep "input" | awk '{sum+=$2; count++} END {print sum/count}'
Monitor Temperature in Real-Time
For continuous monitoring, use watch:
watch -n 1 sensors
This refreshes the output every second.
Alternative: psensors
For a GUI alternative, install psensors:
sudo apt install psensors
Then run psensors to display a graphical interface.
Scripting Example
Here’s a practical script to log CPU temperatures:
#!/bin/bash
while true; do
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
temp=$(sensors -A -u coretemp-isa-0000 | grep "input" | head -1 | awk '{print $2}')
echo "$timestamp: $temp°C" >> /var/log/cpu_temp.log
sleep 60
done
Run this in the background or via cron to periodically log temperatures for trend analysis.
Troubleshooting
If sensors returns no output or error messages:
- Verify the kernel module is loaded:
lsmod | grep coretemp - Load it manually:
sudo modprobe coretemp - Check your BIOS settings — some systems disable sensor access
- On virtual machines, sensors may not be available at all
Check Maximum Temperature Support
View the critical temperature threshold for your CPU:
sensors | grep "crit"
Most modern Intel and AMD CPUs safely handle up to 100°C, but throttling typically starts at 80-90°C depending on the processor.