Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the watch command of linux to execute commands periodically

Shulou Source: shulou.com Published: 2022-06-02 18:07:02 10月04日 Update

This article will explain in detail about the use of linux watch command periodic execution command, Xiaobian feel quite practical, so share to everyone for a reference, I hope you can read this article after harvest.

The watch command executes a given instruction in a periodic fashion, and the output of the instruction is displayed full-screen. 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.

Syntax format: watch [parameter] [command]

Common parameters:

-n/--intervalwatch By default, the program runs every 2 seconds. You can specify the interval time with-n or-interval. -d/--differences The-d or--differences option watch highlights the changing areas. The-d=cumulative option highlights all changes (whether or not the most recent one has changed)-t/--no-title Close watch command Output at the top of the interval, command, current time-h/--help View help documentation

Reference Example

Repeat the uptime command:

[root@linuxcool ~]# watch uptime

Highlight changes in the number of network links every second:

[root@linuxcool ~]# watch -n 1 -d netstat -ant

Average load of output system every 10 seconds:

[root@linuxcool ~]# watch -n 10 'cat /proc/loadavg'

Monitor changes in disk inode and block numbers:

[root@linuxcool ~]# watch -n 1 "df -i;df"

Monitor changes to the test.txt file in the current directory:

[root@linuxcool ~]# watch -d 'ls -l| grep test.txt'about the use of linux watch command periodic execution command to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Command change cycle periodicity time highlight monitor output run utility parameter situation instruction mode more article reference change help good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Xiaomi Shulou Technology Redmi