Friday, April 4, 2008

'Watch'ing your commands running

Sometimes when you run a command, you need to see the progress of the command, yet you do not want to keep refreshing the command by repeating it a few times. There is a useful command in linux that can do the job of refreshing for you which is watch. According to the watch man page: "watch - execute a program periodically, showing output fullscreen". By default watch will refresh the command in the interval of 2 seconds but this can be changed according to your needs.
For example, you want to see the memory usage of your computer every 2 seconds:

$ watch free -m

This kind of output will show:


(Click on the image for clearer view)

To set the interval(15 seconds) which watch will refresh, use -n option:

$ watch -n 15 free -m

The output:


(Click on the image for clearer view)

To see the differences of each refresh session, use -d. Watch will highlight the changes that happening on that particular moment:

$ watch -d free -m


(Click on image for clearer view)

To exit from watch, just use your trusty Ctrl-c

No comments:

Post a Comment