linux--watch使用

watch 命令使用

1.watch命令简介

watch [options] command
The watch program executes a given command at regular inter-vals; the default is every two seconds. The command is passed to the shell (so be sure to quote or escape any special characters), and the results are displayed in a full-screen mode, so you can observe the output conveniently and see what has changed. For example,

每隔一段时间重复运行一个命令,默认间隔时间是2秒。要运行的命令直接传给shell(注意引用和转义特殊字符)。结果会展示为全屏模式,这样你可以很方便的观察改变。例如:

watch -n 60 date 

executes the date command once a minute, sort of a poor man’s clock. Type ^C to exit.
执行date命令每分钟一次,输入^C  退出。

2.Useful options

常用选项

-n seconds Set the time between executions, in seconds.
    设置运行时间间隔,以秒为单位
-d Highlight differences in the output, to emphasize what has changed from one execution to the next.
    高亮输出不同,强调两次执行的不同。

3.watch 手册

NAME
       watch - execute a program periodically, showing output fullscreen
       watch - 定期执行程序,输出全屏

SYNOPSIS
       watch  [-dhvt]  [-n  <seconds>]  [--differences[=cumulative]]  [--help]
       [--interval=<seconds>] [--no-title] [--version] <command>

DESCRIPTION
       watch runs command repeatedly, displaying its output (the first screen-full).   This  allows you to watch the program output change over time.By default, the program is run every 2 seconds; use -n or --interval to specify a different interval.
       监视重复运行命令,展示输出(全屏)。让你监视程序输出变化。默认程序2s运行一次;使用-n或--interval 指定不同的间隔时间

       The  -d  or  --differences  flag will highlight the differences between successive  updates.   The  --differences[=cumulative]  option makes highlighting "sticky",  presenting a running display of all positions that have ever changed.  The -t or --no-title option turns off the header showing  the interval,  command, and current time at the top of the display, as well as the following blank line.
       -d 或 --differences 会高亮显示新内容。--cumulative 选项让高亮保持,展示运行中所有的修改的内容。 -t 或 --no-title 选项关闭头部展示,只展示空白行。

       watch will run until interrupted.
       watch会一直运行,知道中断。

NOTE
       Note that command is given to "sh -c" which means that you may need  to use extra quoting to get the desired effect.
       注意,命令"sh -c" 你需要应用起来才能达到预期的效果。

       Note  that  POSIX  option  processing  is used (i.e., option processing stops at the first non-option argument).  This means that  flags  after command don’t get interpreted by watch itself.
       注意,使用POSIX选项(选项会停在第一个非选项参数)意味着你不能在命令后再设置间隔。

EXAMPLES
       To watch for mail, you might do
       查看邮件

watch -n 60 from

       To watch the contents of a directory change, you could use
       查看目录变化:

watch -d ls -l

       If you’re only interested in files owned by user joe, you might use
       想找joe用户的文件,是下面的命令

watch -d ’ls -l | fgrep joe’

       To see the effects of quoting, try these out
       看引号的使用

     watch echo $$

     watch echo ’$$’

     watch echo ""’$$’""

结束

你可能感兴趣的:(linux)