View watch commands in CentOS
LinuxWatchCommand-to process duplicate tasks
LinuxInWatchCommand provides a way to process repeated tasks. DefaultWatchThe command is repeatedly executed every 2 seconds. Watch is a good tool for observing log files. The following is an example.
watch tail /var/log/syslog
To stop command execution, use the standard kill process [Ctrl] + C.
Watch command to Monitor syslog you can use the-n switch to change and specify the interval. To detect log files every 10 seconds, try this.
watch -n 10 tail /var/log/syslog
LinuxWatch command-watch command with MPs queue
Watch is not limited to viewing log files. It can be used to repeat any command you give it. If you want to monitor the CPU temperature, you can use watch to keep up with the sensord command.
watch -n 1 sensors
The output on my computer looks like this:
acpitz-virtual-0Adapter: Virtual devicetemp1: +45.0°C (crit = +100.0°C)
I want to filter this output to show only the temperature, but not others. I can use this command to view
sensors | grep temp | awk '{ print $2 }'
Remember, the watch command repeats the first command after it. Note that the command is followed by the MPs queue. You can manage your commands in quotation marks.
watch -n1 "sensors | grep temp | awk '{ print $2 }'"
Watch command with Pipeline
Linux watch command -- Use watch as the clock
As you have noticed, watch will display the time in the upper right corner of your terminal after it is executed. We can pass an empty command parameter to watch as a simple clock. We can enclose an empty space in quotation marks as an empty parameter.
watch -n 1 " "
As you can see, this gives this command another meaning, watch ). You can use it as your watch. Now you know how to use the watch command in Linux. What repeated tasks do you want to use it to process?