Linux中实时监控文件改动命令---Watch

watch可以帮你监测一个命令的运行结果,来监测你想要的一切命令的结果变化
watch指令可以间歇性的执行程序,将输出结果以全屏的方式显示,默认是2s执行一次。watch将一直运行,直到被中断。
此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。

参数说明:

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[=]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval   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
参数选项 参数说明
-b, --beep 如果命令的退出不为零(运行正常),则发出‘’哔‘’的警告声
-c, --color 解释ANSI颜色和样式序列
-d, --differences 高亮显示更新之间的更改
-e, --errexit 如果命令的退出不为零(运行正常),则退出
-g, --chgexit 命令输出更改时退出
-n, --interval 间隔<秒>秒之间等待更新
-p, --precise 以精确的间隔尝试运行命令
-t, --no-title 关闭标题
-x, --exec 将命令传递给exec而不是“ sh -c”
-h, --help 显示此帮助并退出
-v, --version 输出版本信息并退出

常用命令案例

watch -n 1 -d  crontab -l   【-n 时间间隔,-d 高亮显示不同】

watch -n 1 -d  netstat -ant  【每隔一秒高亮显示网络链接数的编号情况】

watch -d 'ls /home/error.log'  【高亮查看error日志信息】

watch -t ‘ls /home/error.log’ 【-t 会关闭watch命令在顶部的时间间隔】

watch -n 1 -d 'pstree | grep http' 【每隔一秒高亮显示http链接数的变化情况】

watch -n 1 -d 'netstat -an | grep "21" | egrep "192.168.30.100" | wc -l ' 【实时查看模拟攻击客户机建立起来的连接数】

watch -d ‘ls -l | grep test’ 【检测当前目录中‘test’的文件变化】

watch -n 1 -d “uptime” 【10秒一次输出系统的平均负载】

watch -n 60 from 【每隔一分钟查看邮件】

watch -d ls -l  【高亮查看目录内容的变化】

watch -d ‘ls -l | fgrep admin’ 【如果你只对用户admin拥有的文件感兴趣,可以使用这个查看】

watch echo $$ 【监控脚本运行的当前进程ID号】

watch uname -r 【监视管理员安装最新的内核】


说明:切换终端:Ctrl+x   退出watch:Ctrl+g

你可能感兴趣的:(总结,技术,生产力工具)