-
Book Overview & Buying
-
Table Of Contents
Linux Shell Scripting Cookbook, Second Edition - Second Edition
We might need to continuously watch the output of a command for a period of time in equal intervals. For example, while copying a large file, we might need to watch the growth of the file size. In order to do that, we can use the watch command to execute the du command and output repeatedly. This recipe explains how to do that.
The watch command can be used to monitor the output of a command on the terminal at regular intervals. The syntax of the watch command is as follows:
$ watch COMMAND
For example:
$ watch ls
Or
$ watch 'COMMANDS'
For example:
$ watch 'ls -l | grep "^d"' # list only directories
This command will update the output at a default interval of two seconds.
We can also specify the time interval at which the output needs to be updated, by using -n SECONDS. For example:
$ watch -n 5 'ls -l' #Monitor the output of ls -l at regular intervals of 5 seconds
Let's explore an additional feature of the watch command.
Change the font size
Change margin width
Change background colour