今日,给大家介绍命令watch,使用该命令可以检测终端运行命令的运行情况。
该命令可以用来监测程序输出结果,默认2秒间隔运行,可以使用参数-n 或 -interval 来指定不同的间隔时间。
基本使用方法watch ”需要监测的运行命令”
上文讲过,watch默认2秒间隔运行一次
可选参数我们基本常用的参数如下:
-n set the interval in seconds.
-d flag will highlight the differences between successive updates.
-b option causes the command to beep if it has a non-zero exit.
-e cause watch to exit on an error from the program running.
使用举例#1,高亮显示指定目录的内容
watch -d "ls -alrt /tmp/"#2,终端显示时钟,每1秒更新一次
watch -t -n 1 "date"#3,每隔10秒钟查看占用CPU资源最多的进程
watch 'ps -eo pcpu,pid,user,args | sort -k 1 -n -r | head -10'
