我想知道是否有可能获得CPU温度并将其嵌入命令提示符。
这是我的输出sensors
:
$}-sensors
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +55.0°C (high = +87.0°C, crit = +105.0°C)
Core 0: +55.0°C (high = +87.0°C, crit = +105.0°C)
Core 1: +52.0°C (high = +87.0°C, crit = +105.0°C)
您能告诉我如何使用该grep
功能将温度嵌入到命令提示符中吗?
是的,可以,但是详细信息取决于您的系统。在大多数情况下,命令sensors
应该显示它。
安装必要的软件包
sudo apt-get install lm-sensors
运行sensors-detect
并按照提示进行操作
sudo sensors-detect
如果提示sensors-detect
您安装任何其他驱动程序。
运行sensors
以确保其有效
$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1: +27.8°C (crit = +110.0°C)
temp2: +29.8°C (crit = +110.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +63.0°C (high = +105.0°C, crit = +105.0°C)
Core 0: +62.0°C (high = +105.0°C, crit = +105.0°C)
Core 1: +63.0°C (high = +105.0°C, crit = +105.0°C)
nct6776-isa-0a00
Adapter: ISA adapter
Vcore: +1.86 V (min = +0.00 V, max = +1.74 V) ALARM
in1: +1.36 V (min = +0.00 V, max = +0.00 V) ALARM
AVCC: +3.33 V (min = +2.98 V, max = +3.63 V)
+3.3V: +3.33 V (min = +2.98 V, max = +3.63 V)
in4: +1.01 V (min = +0.00 V, max = +0.00 V) ALARM
in5: +0.00 V (min = +0.00 V, max = +0.00 V)
in6: +0.21 V (min = +0.00 V, max = +0.00 V) ALARM
3VSB: +3.31 V (min = +2.98 V, max = +3.63 V)
Vbat: +3.18 V (min = +2.70 V, max = +3.63 V)
fan1: 0 RPM (min = 0 RPM)
fan2: 3292 RPM (min = 0 RPM)
SYSTIN: +0.0°C (high = +0.0°C, hyst = +0.0°C) sensor = thermistor
CPUTIN: +51.0°C (high = +80.0°C, hyst = +75.0°C) sensor = CPU diode
AUXTIN: +0.0°C (high = +80.0°C, hyst = +75.0°C) sensor = CPU diode
PCH_CHIP_CPU_MAX_TEMP: +58.0°C (high = +80.0°C, hyst = +75.0°C)
PECI Agent 0: +60.0°C (high = +80.0°C, hyst = +75.0°C)
(crit = +105.0°C)
PCH_CHIP_TEMP: +0.0°C
PCH_CPU_TEMP: +0.0°C
intrusion0: OK
intrusion1: OK
beep_enable: disabled
解析输出以仅获取CPU温度。
如您在上面看到的,我系统上的输出与您的系统不同。但是,我们在这里关注的行是相同的。您可以通过以下方式获取CPU温度:
$ sensors | grep -oP 'Physical.*?\+\K[0-9.]+'
63.0
编辑您的~/.bashrc
文件(如果使用其他外壳,则为等效文件),并添加一个运行上述命令的函数:
show_temp(){
sensors | grep -oP 'Physical.*?\+\K[0-9.]+'
}
在提示中使用该功能。例如:
PS1="\u@\h $(show_temp) $ "
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句