Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the examples of using watch?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "what are the examples of watch use". Xiao Bian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "what are the examples of watch use" can help you solve the problem.

watch is a very useful command, basically all Linux distributions have this small tool, as the name, watch can help you monitor the results of a command, save you running it manually over and over again.

1. root@jaking-virtual-machine:~# watch -n 1 cat hello.txtEvery 1.0s: cat hello.txt jaking-virtual-machine: Tue Mar 19 19:13:33 2019Hello World! Hello Jaking! 2. highlight change content root@jaking-virtual-machine:~# watch -d uptime #To highlight changes, use the-d (difference) parameter. Every 2.0s: uptime jaking-virtual-machine: Tue Mar 19 19:14:01 2019 19:14:01 up 3 days, 12:53, 2 users, load average: 0.01, 0.01, 0.00 (omitted here, the change content will be highlighted, very easy to observe) 3. Exit root@jaking-virtual-machine when execution fails:~# watch -n 1 -e cat hello.txt #Run a command, when the exit code is not 0, that is, when the command execution error ends, you can use the-e (errexit) parameter. Every 1.0s: cat hello.txt jaking-virtual-machine: Tue Mar 19 19:16:49 2019

Open another terminal, perform mv operation, you can see the effect:

root@jaking-virtual-machine:~# mv hello. txt/tmp#new terminal root@jaking-virtual-machine:~# watch -n 1 -e cat hello. tmp #old terminal Every 1.0s: cat hello.txt jaking-virtual-machine: Tue Mar 19 19:16:49 2019cat: hello.txt: No such file or directory4. Exit root@jaking-virtual-machine when execution results change:~# watch -n 1 -g 'du -b hello.txt' Every 1.0s: du -b hello.txt jaking-virtual-machine: Tue Mar 19 19:23:41 201927 hello.txt

Open another terminal to perform echo operation, you can see the effect:

root@jaking-virtual-machine:~# echo "watch -n -l -g command" >> hello.txt#new terminal root@jaking-virtual-machine:~# watch -n 1 -g 'du -b hello.txt' #old terminal Every 1.0s: du -b hello.txt jaking-virtual-machine: Tue Mar 19 19:21:55 201950 hello.txt#At this time watch -n 1 -g 'du -b hello.txt' run end root@jaking-virtual-machine:~#About "watch use examples what" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report