Linux watch 命令周期性的执行程序,并全屏显示执行结果

转自:  https://blog.csdn.net/allway2/article/details/91464995

 

 

操作系统笔记: https://blog.csdn.net/qq_41542638/article/details/91399609

LinkedList 源码分析: https://blog.csdn.net/freekiteyu/article/details/93617181

Markdown系列mermaid美人鱼之Flowcharts流程图: https://blog.csdn.net/kl28978113/article/details/93616584

Markdown系列mermaid美人鱼之Gant甘特图: https://blog.csdn.net/kl28978113/article/details/93611438

js判断对象是否为空对象的几种方法: https://blog.csdn.net/couragehope/article/details/93716942

hadoop面试题!这6个!经常问: https://blog.csdn.net/g6U8W7p06dCO99fQ3/article/details/93682463

Spring Cloud、K8S、Netflix OSS三者啥关系:  https://blog.csdn.net/g6U8W7p06dCO99fQ3/article/details/93682497

基于大数据的Uber数据实时监控(Part 2:Kafka和Spark Streaming):  https://blog.csdn.net/g6U8W7p06dCO99fQ3/article/details/93682549

 

阿里p8Java技术专家,他们的能力都需要达到什么程度:  https://blog.csdn.net/g6U8W7p06dCO99fQ3/article/details/93682428

tomcat项目访问路径取消项目名: https://blog.csdn.net/qq_38325614/article/details/93716921

 

Linux watch Command
Sometimes, while working on the Linux command line, you might want to execute a command repeatedly so as to track any change in output. Well, you'll be happy to know there exists a command line utility that lets you do this. The tool in question is Watch, and in this tutorial, we will discuss some of its basic features using some easy to understand examples.

 

But before we do that, it's worth mentioning that all examples used in this article have been tested on Ubuntu 16.04 LTS.

Linux watch command
As already mentioned, the watch utility lets you execute a command repeatedly. Following is the syntax of this command:

watch [options] command
And here's how the tool's man page describes it:

watch runs command repeatedly, displaying its output and errors (the
first screenfull). This allows you to watch the program output change
over time. By default, the program is run every 2 seconds. By
default, watch will run until interrupted.
Following are some Q&A-styled examples that should give you a good idea on how the 'watch' command works.

Q1. How watch command works?
The baisc usage of watch is very easy - all you have to do is to run the tool with a command name as input. For example:

watch date
The above command produced the following output on my system:

The first line of the output tells the output of the command 'date' is being refreshed after every 2 seconds (that's the default time interval), followed by the current date/time of the system. The second line is the actual output of the 'date' command that's getting refreshed after every couple of seconds.

Q2. How to make watch highlight difference between updates?
As already explained in the previous section, the output of the command being tracked is regularly updated (after 2 seconds by default). In case you want, you can also make 'watch' highlight the part of output that's changing between updates.

This you can do using the -d command line option. For example:

watch -d date
And here's how the watch command highlights the changes now:

Q3. How to customize update interval?
As already mentioned, the default update interval is 2 seconds. However, if you want, you can change this value by using the -n command line option, which requires you to pass the new interval value as its input.

For example:

watch -n 5 date
This command will make sure the output gets updated after every 5 seconds. Please note that intervals less that 0.1 seconds aren't allowed.

Note: To make sure the interval gap is honored very precisely, use the -p command line option. Here's how the man page describes this option:

Make watch attempt to run command every interval seconds. Try it
with ntptime and notice how the fractional seconds stays
nearly) the same, as opposed to normal mode where they continu?
ously increase.
Q4. How to turn off the header in output?
If you want, you can also ask 'watch' to turn off the header showing the interval, command, and current
time at the top of the display, as well as the following blank line. This can be done using the -t command line option.

For example:

watch -t date
Here's the output produced by the command above:

So you can see the header was completely stripped off.

Q5. How to make watch exit when the output changes?
If you want the 'watch' command to exit after a change in output is detected, use the -g command line option.

For example:

watch -g free
So anytime the memory consumption in the system changes, the watch command will exit.
--------------------- 
作者:allway2 
来源:CSDN 
原文:https://blog.csdn.net/allway2/article/details/91464995 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值