可使用五种方法实时查看linux系统cpu温度:一、lm-sensors工具;二、读取/sys/class/hwmon下temp_input文件;三、通过/sys/class/thermal/thermal_zone获取温度;四、用hddtemp检查硬盘温度对散热的影响;五、用psensor图形化监控。

如果您在 Linux 系统中需要实时掌握 CPU 温度以评估散热状态,则可能是由于系统负载升高、风扇异常或环境过热导致温度偏高。以下是多种直接有效的查看方法:
一、使用 lm-sensors 工具检测温度
lm-sensors 是专为硬件监控设计的成熟工具,可识别主板、CPU 和芯片组内置的温度传感器,并提供带阈值(high/crit)的结构化输出,便于判断是否处于安全范围。
1、根据发行版安装 lm-sensors:
Debian/Ubuntu 系统执行:sudo apt-get install lm-sensors -y
CentOS/RHEL 7/8 执行:sudo yum install lm_sensors -y
CentOS/RHEL 9 或 Fedora 执行:sudo dnf install lm_sensors -y
2、运行自动探测脚本并接受全部默认选项:sudo sensors-detect
3、加载内核模块后,执行命令查看实时温度:sensors
二、读取 /sys/class/hwmon 下原始温度文件
/sys/class/hwmon 是 Linux 内核暴露的硬件监控接口,所有温度值以毫摄氏度(m°C)为单位存储于 temp*_input 文件中,无需额外依赖,适合脚本化调用和嵌入式环境。
1、列出所有硬件监控设备目录:ls /sys/class/hwmon/
2、依次查看各 hwmon 目录下的传感器名称与温度值:for dir in /sys/class/hwmon/hwmon*; do echo "$dir:"; cat "$dir/name" 2>/dev/null; cat "$dir/temp*_input" 2>/dev/null | awk '{printf "%.1f°C\n", $1/1000}'; done
3、若需单独获取 CPU Package 温度,可尝试定位包含 coretemp 或 k10temp 的 hwmon 子目录,再读取对应 temp1_input。
三、通过 /sys/class/thermal 获取 thermal_zone 温度
thermal 子系统面向热管理策略设计,其 thermal_zone* 目录提供更语义化的温度节点(如 cpu-thermal、x86_pkg_temp),数值同样为毫摄氏度,且部分 zone 支持 mode、policy 等控制接口。
1、列出所有 thermal 区域:ls /sys/class/thermal/
2、查看某 thermal_zone 的类型与当前温度:cat /sys/class/thermal/thermal_zone*/type /sys/class/thermal/thermal_zone*/temp 2>/dev/null | paste -d': ' - - | awk -F': ' '{printf "%s → %.1f°C\n", $1, $2/1000}'
3、快速筛选含 “cpu” 或 “pkg” 字样的 zone 并显示温度:for z in /sys/class/thermal/thermal_zone*; do [ -f "$z/type" ] && grep -q -i "cpu\|pkg" "$z/type" && echo "$(cat $z/type): $(awk '{printf "%.1f°C", $1/1000}' $z/temp)"; done
四、使用 hddtemp 辅助验证硬盘温度是否影响整体散热
硬盘持续高负载运行会产生可观热量,尤其在 NAS 或密集存储场景下,其温度可能间接推高机箱内部环境温度,进而影响 CPU 散热效率。
1、安装 hddtemp 工具:sudo apt-get install hddtemp -y(Debian/Ubuntu)或 sudo dnf install hddtemp -y(Fedora/RHEL)
2、检测支持的硬盘设备并读取温度:sudo hddtemp /dev/sda
3、批量扫描所有 ATA/SATA 硬盘:sudo smartctl --scan | awk '{print $1}' | xargs -I{} sudo hddtemp {} 2>/dev/null | grep -E "(#|°C)"
五、启用 psensor 图形界面进行可视化监控
psensor 是基于 GTK 的图形化传感器监视器,可同时聚合 lm-sensors、hddtemp、NVIDIA GPU 温度等数据,并支持历史曲线绘制与告警阈值设置,适用于桌面环境下的长期温控观察。
1、安装 psensor 及其依赖:sudo apt-get install psensor lm-sensors hddtemp -y
2、确保 sensors-detect 已完成配置,且 sensors 命令可正常输出数据
3、启动图形界面:psensor,首次运行时将引导添加传感器;勾选“显示在顶部栏”可启用常驻温度指示器










