Linux Watch Command Tutorial With Examples – POFTUT

Linux Watch Command Tutorial With Examples

Some time generally long-running operations like copying disk need to track the change like disk usage or change of the size of the file. We generally run the same command again and again but this is a very cumbersome way yo see progress. Linux users created a “watch” application to make things better. When we use “watch” we can get change with specified interval times.

Syntax

We will use options to change behavior of the watch command. COMMAND is the command we want to run with given intervals.

Help

We can print help information about the watch command with the -h option.

Help

Help

Just Watch

We will use watch command without providing any options. We will provide ls -lh command and run this command at 2 seconds interval. The default interval is 2 seconds.

Just Watch

Just Watch

As we can see from screenshot all files and folders are listed and will be refreshed in 2 seconds interval.

Exit or Quit

While running watch it will not end automatically. We must kill the watch process if we want to end. The simple way to end watch is using the following shortcut.

Set Interval

Default interval value for the watch is 2 seconds. In each interval provided command runs and the output is refreshed. We may need to change 2 seconds interval more suitable for our situation. -n option can be used to change the default interval. We change ls -lh command interval to 5 seconds in the following example.

LEARN MORE  How To Pause and Resume Powershell and Cmd Scripts In Windows With Examples?

Set Interval

Set Interval

Remove Header

We can remote the watch title so we just get command output if we want to use the output from different applications.

Remove Header

Remove Header

Play Beep If There Is Change

As watch commands run provided command periodically. If there is no change the provided command provides 0 as output. If there is change there will be a non zero change which means there is a change. wait command can play a beep sound if the output is non-zero. We will provide the -b or --beep option.

Play Beep If There Is Change

Play Beep If There Is Change

 

Linux Watch Command Tutorial With Examples Infographic

Linux Watch Command Tutorial With Examples Infographic

Linux Watch Command Tutorial With Examples Infographic

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)