Linux 下获取 CPU 温度

搞了个台式机,好久没碰物理设备了…天气较热,就做了下相关的搜索,除了安装一些辅助工具的办法,系统其实原生提供了接口

getTemp () {
  for zone in `ls /sys/class/thermal/ | grep thermal_zone`
  do
    echo -n "`cat /sys/class/thermal/$zone/type`: "
    echo `cat /sys/class/thermal/$zone/temp | sed 's/\(.\)..$/.\1°C/'`
  done
}

另外,注意到温度还有一点是因为 Ubuntu (22.04) 登录时会在 motd 上显示。Ubuntu MOTD 的配置位于 /etc/update-motd.d/。温度信息的来源是:

  • /etc/update-motd.d/50-landscape-sysinfo
  • /usr/bin/landscape-sysinfo (package: landscape-common)
  • /usr/lib/python3/dist-packages/landscape/sysinfo/temperature.py
  • /usr/lib/python3/dist-packages/landscape/lib/sysstats.py

参考:

Some rights reserved
Except where otherwise noted, content on this page is licensed under a Creative Commons Attribution-NonCommercial 4.0 International license.