Linux watch命令

Linux watch命令可以动态监测一个命令的运行结果,常见用法如下:

root@ubuntu:/home/run/code# watch -h

Usage:
 watch [options] command

Options:
  -b, --beep             beep if command has a non-zero exit
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates     ## 高亮显示变化
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates  ## 间隔时间,以秒为单位
  -p, --precise          attempt run command in precise intervals
  -t, --no-title         turn off header
  -x, --exec             pass command to exec instead of "sh -c"

 -h, --help     display this help and exit
 -v, --version  output version information and exit

For more details see watch(1).

举例:

动态监测CPU温度变化,命令:

## 每隔1秒,显示soc的温度(除以1000),并高亮显示变化部分
root@linaro-alip:# cat /sys/class/thermal/thermal_zone0/type
soc-thermal
root@linaro-alip:/# watch -n 1 -d cat /sys/class/thermal/thermal_zone0/temp
Every 1.0s: cat /sys/class/thermal/the...  linaro-alip: Mon Aug 16 14:49:27 2021

31666

## 每隔1秒,显示gpu的温度,并高亮显示变化部分
root@linaro-alip:# cat /sys/class/thermal/thermal_zone1/type
gpu-thermal
root@linaro-alip:/# watch -n 1 -d cat /sys/class/thermal/thermal_zone1/temp
Every 1.0s: cat /sys/class/thermal/the...  linaro-alip: Mon Aug 16 14:49:39 2021

32777

上面测试例子基于RockPi 4A Linux4.4内核。

{{o.name}}
{{m.name}}

猜你喜欢

转载自my.oschina.net/u/4702401/blog/5379220