Linux Watch Command Tutorial With Examples
Some time generally long running operations like copying disk needs to track the change like disk usage or change of size of file. We generally run same command again and again but this is 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.
We will use options with to change behavior of the
watch command. COMMAND is the command we want to run with given intervals.
watch [OPTIONS] COMMAND
We can print help information about the
watch command with the
$ watch -h
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
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 following shortcut.
Default interval value for 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 default interval. We change
ls -lh command interval to 5 seconds in the following example.
$ watch -n 5 ls -lh
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