Introduction
Like any electrical component, CPUs generate heat when being used. Some resource-demanding programs cause the CPU to increase the clock speed, which results in higher temperatures. Dust buildup also causes the CPU to overheat.
High temperatures shorten the lifespan of sensitive components, so keeping track of CPU temperatures is crucial. This way, you prevent performance throttling or component damage.
In this tutorial, you will learn how to use different tools and in-built utilities to check CPU temperature on Linux machines.
Prerequisites
- A machine running Linux
- An account with sudo/root privileges
Check CPU Temperature Using Lm-Sensors
Lm-sensors is a command-line utility for hardware monitoring. Use the tool to check the temperature of the CPU and other components. Follow these steps to install and configure Lm-sensors:
1. Open the terminal and install these packages using a package manager for your distribution. In Ubuntu, use the following command:
sudo apt install hddtemp lm-sensors
Wait for the lm-sensors and hddtemp to finish downloading and installing.
2. Execute the sensors
command to see the CPU temperature. The output shows the current temperature readings of all sensors in the machine. The results include the temperature of each core and maximum thresholds.
3. To check SSD and hard drive temperatures, execute the following command:
sudo hddtemp /dev/sda
The output shows the temperature of the selected disk.
4. To see which system components you can monitor, run sudo sensors-detect
.
Answer YES to multiple scanning requests until the system scan is complete.
When the scan completes, the output shows the summary.
5. To ensure that system monitoring works, load the needed modules using the following command:
/etc/init.d/kmod start
6. To run the sensors
command repeatedly and get real-time data in the terminal, execute the following command:
watch sensors
The output refreshes every two seconds and displays the current CPU temperature reading.
Note: To check CPU usage on Linux, read our tutorial on How to check CPU usage.
Check CPU Temperature Using Psensor
Psensor is a GUI app that allows you to monitor the temperature of various system components. This utility also allows you to monitor CPU usage and fan speed.
Psensor includes an applet indicator for Ubuntu, allowing you to display the temperature in the top panel to notify you when the temperatures get too high.
Install Psensor
Before installing Psensor, you need to install and configure Lm-sensors.
1. Run this command to install the necessary packages:
sudo apt install lm-sensors hddtemp
2. Next, scan for sensors in your machine:
sudo sensors-detect
Answer YES to any scan requests until the scan is completed.
3. To make sure the packages are installed, execute the sensors
command.
4. Update the package repository with sudo apt update
.
5. Install Psensor using the following command:
sudo apt install psensor
Answer YES and wait for the installation to finish.
Using Psensor
Search for Psensor in the app menu and open the utility. The app displays a graph of the selected values and shows the CPU temperature, CPU and memory usage, free RAM, GPU temperature, and HDD temperature.
To configure Psensor and set which stats you want to see, follow these steps:
1. Click Psensor in the menu bar, followed by Preferences.
2. Check off the boxes for the options you want – whether Psensor launches on system startup, the update interval, graph colors, etc.
3. To show CPU or HDD temperatures in the top panel, go to Sensor Preferences under the Application Indicator. Enable the Display sensor in the label option.
Note: Learn more about monitoring CPU performance by referring to our article on Linux perf, a lightweight command-line utility.
Check Temperature Without Third-Party Utilities
There is a way to use the in-built utilities to check the CPU temperature if you don’t want to use third-party apps.
1. To check the CPU temperature without installing a third-party app, use the following command:
cat /sys/class/thermal/thermal_zone*/temp
The output shows the CPU temperature in the five-digit format. Here, 49000 means 49C.
2. If you get several thermal zones and different temperatures, execute the following command to see what a single thermal zone represents:
cat /sys/class/thermal/<thermal_zoneNumber>/type
For example, run cat /sys/class/thermal/thermal_zone2/type
to see the type of thermal zone 2.
The CPU temperature is in the zone labeled x86_pkg_temp.
3. To see what all the thermal zones are referring to, use:
paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/'
The output shows the last stored temperature for that thermal zone in degrees Celsius. In this example, there is only one thermal zone, labeled x86_pkg_temp, which represents the CPU temperature.
Conclusion
You now know how to check CPU temperature on Linux using various utilities. The guide also showed how to configure the tools to display other information, such as GPU and HDD temperature.