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.
watch [OPTIONS] COMMAND
Help
We can print help information about the watch
command with the -h
option.
$ watch -h

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.
$ watch ls -lh

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.
CTRL+c
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.
$ watch -n 5 ls -lh

Remove Header
We can remote the watch title so we just get command output if we want to use the output from different applications.
$ watch -t ls -lh

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.
$ watch -b ls /home/ismail

Linux Watch Command Tutorial With Examples Infographic
