View watch commands in CentOS

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.