zoukankan      html  css  js  c++  java
  • 每天一个Linux命令(42)watch命令

        watch命令以周期性的方式执行给定的指令,指令输出以全屏方式显示。

        (1)用法:

        用法:  watch  [参数]  [命令]

     

        (2)功能:

        功能:  可以将命令的输出结果输出到标准输出设备,多用于周期性执行命令/定时执行命令。

        FreeBSD和Linux下watch命令的不同,在Linux下,watch是周期性的执行下个程序,并全屏显示执行结果,如:watch -n 1 -d netstat -ant,而在FreeBSD下的watch命令是查看其它用户的正在运行的操作,watch允许你偷看其它terminal正在做什么,该命令只能让超级用户使用。

        (3)选项参数:

        1)  -d:        高亮显示指令输出信息不同之处;

        2)  -n --interval      可以用-n或-interval来指定间隔的时间。

        3)  -t:          不显示标题。

        (4)实例:

          1)[root@localhost sunjimeng]# watch ls -l        以全屏的方式显示watch后的命令的查询结果(默认每2秒更新一次)

    Every 2.0s: ls -l                                                                             Tue Jun  7 23:36:39 2016
    
    总用量 4
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Desktop
    drwxrwxr-x. 4 sunjimeng users     4096 5月  28 00:24 Document
    drwxr-xr-x. 4 root    sunjimeng   48 6月   7 23:34 Documents
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Downloads
    drwxrwxr-x. 2 sunjimeng sunjimeng    6 5月  17 04:55 findTextDir
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Music
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Pictures
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Public
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Templates
    drwxr-xr-x. 2 sunjimeng sunjimeng    6 5月   1 01:23 Videos

          2)[root@localhost sunjimeng]# watch -n 5 netstat -ntlp      以每5秒执行一次的方式全屏显示命令执行的结果

    Every 5.0s: netstat -ntlp                                                                     Tue Jun  7 23:40:28 2016
    
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State    PID/Program name
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN    1282/sshd
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN    3269/cupsd
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN    2527/master
    tcp6       0      0 :::22                   :::*                    LISTEN    1282/sshd
    tcp6       0      0 ::1:631                 :::*                    LISTEN    3269/cupsd
    tcp6       0      0 ::1:25                  :::*                    LISTEN    2527/master

          netstat显示网络链接数的变化情况。

          3)[root@localhost Documents]# watch -t ls -l         不显示标题

    Every 2.0s: ls -l                                                                             Tue Jun  7 23:46:54 2016
    
    总用量 0
    drwxr-xr-x. 2 root root 72 5月  31 18:25 grepDir
    -rw-r--r--. 1 root root  0 6月   7 23:34 myfile
    drwxr-xr-x. 2 root root  6 6月   7 23:33 newWatch
    总用量 0
    drwxr-xr-x. 2 root root 72 5月  31 18:25 grepDir
    -rw-r--r--. 1 root root  0 6月   7 23:34 myfile
    drwxr-xr-x. 2 root root  6 6月   7 23:33 newWatch

        4)[root@localhost Documents]# watch 'ps aux|grep httpd'        查看某个进程,定时刷新,比较常用。

    Every 2.0s: ps aux|grep httpd                                                                 Tue Jun  7 23:50:35 2016
    
    root      21479  0.0  0.0 125424  1740 pts/2    S+   23:50   0:00 watch ps aux|grep httpd
    root      21514  0.0  0.0 125420   460 pts/2    S+   23:50   0:00 watch ps aux|grep httpd
    root      21515  0.0  0.0 113116  1384 pts/2    S+   23:50   0:00 sh -c ps aux|grep httpd
    root      21517  0.0  0.0 112656   952 pts/2    S+   23:50   0:00 grep httpd
  • 相关阅读:
    动态代理
    构建一个REST风格的Web服务(Building a RESTful Web Service)
    使用Spring Boot构建应用程序(Building an Application with Spring Boot)
    SpringBoot笔记 三
    SpringBoot笔记 一
    redis的linux安装
    mysql的windows安装
    linux下Redis安装
    上网列表
    shell每日发邮件
  • 原文地址:https://www.cnblogs.com/MenAngel/p/5570091.html
Copyright © 2011-2022 走看看