..
watch命令
今年在查看端口情况使用到了watch命令,如果我要实时的查看当前系统的端口使用情况,这样写:
watch -n 1 "netstat -ant"
显示结果如下:
Every 1.0s: netstat -ant Thu Feb 8 22:25:55 2018
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN
tcp 0 0 172.17.220.102:22 221.217.218.194:49390 ESTABLISHED
tcp 391 0 172.17.220.102:51760 106.11.68.13:80 CLOSE_WAIT
tcp 401 0 172.17.220.102:50192 140.205.140.205:80 CLOSE_WAIT
tcp 0 0 172.17.220.102:56940 106.11.68.13:80 ESTABLISHED
tcp 401 0 172.17.220.102:57060 140.205.140.205:80 CLOSE_WAIT
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 :::7000 :::* LISTEN
如果我执行查看80端口的情况,那么可以加入grep
watch -n 1 "netstat -ant | grep 80"
这里解释一个watch这个命令用户,以及命令参数。watch主要是用来重复执行命令,被双引号包含起来的就是你要重复执行的命令.
[root@iZ2zefvnzjphkalt990sg0Z ~]# watch -h
Usage:
watch [options] command
Options:
-b, --beep 如果被执行的命令返回了非0值,那么出发出蜂鸣报警
-c, --color interpret ANSI color and style sequences
-d, --differences[=<permanent>]
高亮实现两个命令不同结果
-e, --errexit 如果命令返回了非0值,那么退出
-g, --chgexit 如果相比上一次输出发生了变化,那么退出
-n, --interval <secs> seconds to wait between updates
-p, --precise attempt run command in precise intervals
-t, --no-title 不显示命令标题
-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).